SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: Dynamic form question ?
-
Aug 27, 2003, 15:35 #1
- Join Date
- Aug 2003
- Location
- Sweden
- Posts
- 9
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Dynamic form question ?
Hello!
I do have this dynamic order form which works fine.
How do I please make so I can have some text before the prices in the menus please?
Code:<form> <select name="a" onchange="this.form.summa.value=parseFloat(this[this.selectedIndex].text)+parseFloat(this.form.b[this.form.b.selectedIndex].text)"> <option>79</option><option>79</option><option>99</option><option>109</option><option>139</option> </select> <select name="b" onchange="this.form.summa.value=parseFloat(this[this.selectedIndex].text)+parseFloat(this.form.a[this.form.a.selectedIndex].text)"> <option>0</option><option>80</option><option>160</option><option>300</option><option>500</option> </select> <input type="text" name="summa" value=""> </form>
-
Aug 27, 2003, 18:12 #2
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
the easiest method (while keeping your code intact) would be to put the option's text within the value
Code:<select name="a" onchange="this.form.summa.value=parseFloat(this[this.selectedIndex].value)+parseFloat(this.form.b[this.form.b.selectedIndex].value)"> <option value='79'>Some text</option>
VinnyWhere the World Once Stood
the blades of grass
cut me still
-
Aug 27, 2003, 18:37 #3
- Join Date
- Aug 2003
- Location
- Sweden
- Posts
- 9
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi!
I did try that now, but that always gives the total price "NaN". Thanks anyway.
all code now:
Code:<form> <select name="a" onchange="this.form.summa.value=parseFloat(this[this.selectedIndex].value)+parseFloat(this.form.b[this.form.b.selectedIndex].value)"> <option value='79'>Some text</option> <option>99</option><option>109</option><option>139</option> </select> <select name="b" onchange="this.form.summa.value=parseFloat(this[this.selectedIndex].text)+parseFloat(this.form.a[this.form.a.selectedIndex].text)"> <option>0</option><option>80</option><option>160</option><option>300</option><option>500</option> </select> <input type="text" name="summa" value=""> </form>
-
Aug 28, 2003, 05:25 #4
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
You getting 'NAN' because you didn't change all of the options. Also, you will be unable to get the 1st calculation without selecting and reselecting because of the onchange handler.
Why aren't you using a function? Something like:
Code:function doit(formObj, selA, selB) { formObj.summa.value = parseFloat(selA.options[selA.selectedIndex].value) + parseFloat(selB.options[selB.selectedIndex].value) }
Code:<form> <select name="a" onchange="doit(this.form,this.form.a,this.form.b)"> <option value='0'>a</option> <option value='80'>b</option> </select> <select name="b" onchange="doit(this.form,this.form.a,this.form.b)"> <option value='10'>c</option> <option value='180'>d</option> </select> <input type="text" name="summa" onfocus="doit(this.form,this.form.a,this.form.b)"> <input type="button" value='do it' onclick="doit(this.form,this.form.a,this.form.b)"> </form>
Where the World Once Stood
the blades of grass
cut me still
-
Aug 28, 2003, 09:11 #5
- Join Date
- Aug 2003
- Location
- Sweden
- Posts
- 9
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks a lot for the help.
-
Aug 28, 2003, 11:32 #6
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
no prob
VinnyWhere the World Once Stood
the blades of grass
cut me still
Bookmarks