Forum Moderators: open

Message Too Old, No Replies

SELECT to CHANGE textField values

JS to change Textbox Value..multiple times

         

jdwalters

7:02 pm on May 26, 2003 (gmt 0)

10+ Year Member



hi,
I need help, urgently! :)
I am busy with a page on which I need to change a value in a text box using 2 or 3 select drop-downs.

I manage to do this using this:
<form>
<input type="text" name="txtTarget" value=2>
<SELECT size="5" onchange="this.form.txtTarget.value=parseInt(this.form.txtTarget.value) + parseInt(this.options[this.selectedIndex].value);">
<option value=5>Blue (add $5)</option>
<option value=10>Red (add $10)</option>
</SELECT>
</form>

But, when I change it to another option, it keeps adding the total, I need it to go back to the original value and add the new option selected.

Another thing I need is another value (ID) called from a DB to be carried over to the next page, so if the user selected "Blue (add $5)" that option's ID from the DB must be carried over... I hope I made this clear enough.

Please someone - I'm very new to this and need help... thanks

Jacques

jatar_k

8:34 pm on May 26, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld jdwalters,

I need help, urgently!
don't we all ;)

how about

onchange="this.form.txtTarget.value=2 + parseInt(this.options[this.selectedIndex].value);"

don't know if you need to leave the parseInt in there, I wouldn't think so but you can try it.

As far as passing values goes, I have never done it with javascript only server side scripting languages so someone else may have the answer for that.

jdwalters

6:39 am on May 27, 2003 (gmt 0)

10+ Year Member



Thanx,

I realize that server-side should work better in this case, so I've gone that way.

I just thought if I could have it client-side everything would be a bit faster, but we can't have our way always now, can we?

c ya l8r!

BlobFisk

9:05 am on May 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, jdwalters!

You can pass a variable from one page to another using JavaScript by adding the variable to the URL. This can be done on the form, my using method="link":


<FORM METHOD="LINK" ACTION="receivingPage.html">

This will add the variables from your form to the URL:


www.domain.com/receivingPage.html?firstName=Jane&surName=Doe

You can then use some JavaScript on the receiving page to strip out the variables from the url.

HTH