Using javascript - onchange="this.form.submit()

Discussion in 'HTML & Website Design' started by oehq, Mar 24, 2016.

  1. #1
    I am writing a page that uses Coldfusion and the javascript onchange="this.form.submit() in a select statement.

    The form's submit calls itself, So if I use a submit button the submit buttons objects name can be checked with a isdefined("submit button") at the top of the page to control the code flow.

    How do I send the objects name when I use the " onchange="this.form.submit()" so I know where the user came from i.e what select he used?

    I can get the form to submit but the cfdump of the form variables does not appear to show a name of the control user used to submit the form?

    Is there anyway to check what control the user used to submit the page?

    Hope this make sense

    Thanks for the help
     
    oehq, Mar 24, 2016 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    Generally speaking if you are using ANY of the onevent attributes, you're likely doing something wrong... but really we'd have to see what you have for code so far to say what exactly it is you are doing wrong.

    IF it's just one select inside the form, don't use a form, use anchors and skip the scripttardery entirely. (you see that idiocy in forum software all the damned time). If there's more data being chosen than just the select, THAT's when you may have to resort to scripttardery but you should STILL have a proper submit (that you hide when scripting works) so people with JS blocked or unavailable can still use your page. Remember the unwritten rule of JavaScript: "If you cannot make your page fully functional without JavaScript first, you likely have zero business adding scripting to it!".

    Though... Coldfusion? REALLY? People still use that?

    Can we see the full form you are trying to manipulate? Could be you're missing something simple.... could be as simple as using CSS to fake the appearance of a select on a DIV or fieldset filled with different <input type="submit"> that have different names. Server-side only the submit that's clicked on has its name and value submitted. (which is why if you don't care about multiple submits avoid putting name on the submit, it's wasting bandwidth) -- again, a scriptless solution.

    99% of the time someone says to slap JavaScript on a form to provide functionality instead of a simple enhancement? DON'T!!!
     
    deathshadow, Mar 25, 2016 IP