2 Replies - 3255 Views - Last Post: 22 July 2016 - 10:04 AM Rate Topic: -----

#1 Carjunkie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-March 16

Howto set a form variable from javscript onchange='this.form.subm

Posted 25 March 2016 - 10:30 AM

I'm hoping there might be a easy answer to the issue below.
I have a page with a form and the form submit calls the exact same page the form is on. When I check the form variables after the button submit the form.button2 variable exist and has a value when using a button to submit the page.

However, when submitting the page via onchange='this.form.submit()' no form variable is updated to reflect that the user submitted the page. Is there a way to force a form variable to update so I can see that the user came form this control via javascript?


See sample code below and screen shot below

example code...

xxxxxxxxxxxxxxx    Example with submit button.   xxxxxxxxxxxxxxxxx

<cfdump var="#form#" label="testit">

<cfif isdefined("form.button2")>
  <!--- Do somthing Here--->
</cfif>

<cfform name="testit" action="test.cfm">
<select name='myfield'>
  <option selected="selected"> --- Pick Drink ---</option>
  <option >Milk</option>
  <option>Coffee</option>
  <option>Tea</option>
</select>
<input type="submit"  name="button2" value="Submit">
</cfform>




XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


Notice, when I use the onchange='this.form.submit()' then there no button and nothing to test to see that the user came from this control

xxxxxxxxxxxxxxx Example with javascript no button. xxxxxxxxxxxxxxxxx
<cfdump var="#form#" label="testit">
<cfform name="testit" action="test.cfm">
<select name='myfield' onchange='this.form.submit()'>
  <option selected="selected"> --- Pick Drink ---</option>
  <option >Milk</option>
  <option>Coffee</option>
  <option>Tea</option>
</select>
</cfform>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX





************** Here are the dump results with and without the submit button

any Ideas would be greatly appreciated

Thanks

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Howto set a form variable from javscript onchange='this.form.subm

#2 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 2024
  • View blog
  • Posts: 3,609
  • Joined: 13-January 08

Re: Howto set a form variable from javscript onchange='this.form.subm

Posted 25 March 2016 - 12:50 PM

Welcome to DIC Carjunkie!

So, to answer your question: of course, there is a way to get this form to tell you whether the user clicked a button or whether they changed the value of the dropdown field.

The easiest way would be to set a hidden form variable and set it to a default value. Then, rather than using the onchange event to execute Javascript straight in the attribute value...have it call a Javascript function that first changes the value in the hidden form field and then submits the form.

On the receipt end, you can tell which method the user used to submit the form depending upon which value you see for the hidden form field.

Good luck!
Was This Post Helpful? 0
  • +
  • -

#3 coatimundi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-July 16

Re: Howto set a form variable from javscript onchange='this.form.subm

Posted 22 July 2016 - 10:04 AM

Buttons are not registered into the FORM collection on postback if they're not clicked, just as checkboxes/radios are not registered if they're not checked.
You can try document.getElementById('yourButtonID').click()

http://www.w3schools..._html_click.asp

I recall there being some restrictions on what you could call click on in some browsers, and a form submission may be one of those.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1