Im a bit stuck here. I am trying to get the value from a JavaScript function and place it in to the VALUE of a HIDDEN field. Does anybody know how to do this. An extract of my code is below:
<SCRIPT LANGUAGE="JavaScript">
function popItUp() {
//creating a new window and loading it with contact.html
var newWindow = open("shipping.html", "secondWindow", "width=300,height=400");
}
function ChangeItem(lens,frame,price) {
document.ProductForm.Detail1.value = lens
document.ProductForm.Detail2.value = frame
document.ProductForm.Price.value = price
document.ProductForm.BasePrice.value = price
}
</script>
</head>
<div align="center">
<form name='ProductForm' method='post' action='test2.php'>
<input type="radio" name="LenFrameID" value="16478" onClick="ChangeItem('Black Violet','Black','84.95')"
CHECKED>
<br>
<input type="radio" name="LenFrameID" value="16479" onClick="ChangeItem('Violet','Blue','88.95')">
<input type="hidden" name="BasePrice" value="HOW DO I GET VALUE OF BASEPRICE HERE">
<input type='submit' value='Continue'>
</tr>
</form>
PHP + Javascript
Moderator: General Moderators
-
Stoneguard
- Forum Contributor
- Posts: 101
- Joined: Wed Aug 13, 2003 9:02 pm
- Location: USA
Are you wanting to double check it is working? The code looks fine, although I typically don't use the form name. Just add an alert to give you an idea if the value is set:
Code: Select all
<SCRIPT LANGUAGE="JavaScript">
function popItUp() {
//creating a new window and loading it with contact.html
var newWindow = open("shipping.html", "secondWindow", "width=300,height=400");
}
function ChangeItem(lens,frame,price) {
var fm = document.ProductForm;
fm.Detail1.value = lens
fm.Detail2.value = frame
fm.Price.value = price
fm.BasePrice.value = price
alert(fm.BasePrice.value);
}
</script>
</head>
<div align="center">
<form name='ProductForm' method='post' action='test2.php'>
<input type="radio" name="LenFrameID" value="16478" onClick="ChangeItem('Black Violet','Black','84.95')"
CHECKED>
<br>
<input type="radio" name="LenFrameID" value="16479" onClick="ChangeItem('Violet','Blue','88.95')">
<input type="hidden" name="BasePrice" value="HOW DO I GET VALUE OF BASEPRICE HERE">
<input type='submit' value='Continue'>
</tr>
</form>-
TheWaterboy08
- Forum Newbie
- Posts: 4
- Joined: Wed Oct 15, 2003 10:12 am
the code is okay. My problem is that I cannot put the value that is set in the price variable on the CahngeItem function into the hidden input value field as I dont know how. The reason is that for each checkbox there is a differnet price. If a checkbox is clicked I need the price so the variable is set each time. How do i get this variable into a hidden field
-
Stoneguard
- Forum Contributor
- Posts: 101
- Joined: Wed Aug 13, 2003 9:02 pm
- Location: USA
You can pass in the fld itself to easily get teh alue, or you can loop through all the fields in the array to check which one is checked.
I recommend something like this:
note the added parameter called 'this'. That parameter actually returns the exact control in which it sits, so 'fld.value' in the function will get 16478 for the row above.
I recommend something like this:
Code: Select all
...
function ChangeItem(lens,frame,price, fld) {
var fm = document.ProductForm;
fm.Detail1.value = lens
fm.Detail2.value = frame
fm.Price.value = price
fm.BasePrice.value = fld.value
alert(fm.BasePrice.value);
}
</script>
...
<input type="radio" name="LenFrameID" value="16478" onClick="ChangeItem('Black Violet','Black','84.95', this)"
...