473,614 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need to get a value in a form?

I have a form that has a select list.

A user chooses a value and the page refreshes showing the selected
value in the dropdown box.

So I want to use Javascript to get the selected query from the form.

I then want to pass it as a hidden field.

So for example the section of the page I'm interested in will look like
this.

<form action="asubmit page.htm" method="post">

<select name="ent" onchange="form. submit();">
<option value="UK">UK</option>
<option selected value="USA">USA </option>
<option value="JAPAN">J APAN</option>
<option value="UK">UK</option>
</select>

I then want to take the selected value and submit it as a hidden field.

<form action="setpov. htm" method="post">
<input type="hidden" name="Entity" value=" this is where i want to fill
this with the selected value ">
</form>

I take it javascript is the easiest way to do this.

Regards

Craig

Jul 23 '05 #1
5 1876
In article <11************ **********@g47g 2000cwa.googleg roups.com>,
cm*******@yahoo .co.uk enlightened us with...
I have a form that has a select list.

A user chooses a value and the page refreshes showing the selected
value in the dropdown box.

So I want to use Javascript to get the selected query from the form.

I then want to pass it as a hidden field.


Why?
Planning to pass on this value in a series of pages?
If so, javascript is not the best solution. You may want to consider server-
side-scripting.

If you still want to do it this way, just have the hidden field already there
and use JS to fill in the value from the querystring.
http://www.ipwebdesign.net/kaelisSpa..._parseUrl.html

--
--
~kaeli~
She was engaged to a boyfriend with a wooden leg but broke
it off.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
Why? Because I need to and if i had to explain why then i'd totally
confuse people!

I looked at your example using Firefox and it didn't work.

Jul 23 '05 #3
cm*******@yahoo .co.uk wrote:
I have a form that has a select list.

A user chooses a value and the page refreshes showing the selected
value in the dropdown box.

So I want to use Javascript to get the selected query from the form.

I then want to pass it as a hidden field.

So for example the section of the page I'm interested in will look like
this.

<form action="asubmit page.htm" method="post">

<select name="ent" onchange="form. submit();">
<option value="UK">UK</option>
<option selected value="USA">USA </option>
<option value="JAPAN">J APAN</option>
<option value="UK">UK</option>
</select>

I then want to take the selected value and submit it as a hidden field.

<form action="setpov. htm" method="post">
<input type="hidden" name="Entity" value=" this is where i want to fill
this with the selected value ">
</form>

I take it javascript is the easiest way to do this.


Your explanation is very confusing. As far as I can tell, you have two
forms. When an option is selected in one form, you want that form to
submit, then re-load the same page with the selected option as the
default selected.

e.g. if I selected "JAPAN", the form submits and the page loads with
"JAPAN" as the default selected, not "USA".

When the page loads, you want to copy the value of the selected option
to a hidden field in another form. Is that it? Seems unusual, but
you're obviously keen to do it.

The obvious solutions are:

1. Have one form and submit it all in one go, no need for the onchange
submit.

2. When the first form submits, return the selected value in the hidden
field. You say this isn't an option, yet you must be going to
change the default selected option anyway.

Given neither of the above seems appropriate:

3. Have the second form get the value of the selected option when it
submits. Then the first doesn't need to submit at all (submitting
onchange is nasty at any time - the user has to repost the form if
they make a simple slip-up).

4. Have an onload function that gets the value of the selected option
and puts it into the hidden field in the second form.

--
Rob
Jul 23 '05 #4
In article <11************ **********@f14g 2000cwb.googleg roups.com>,
cm*******@yahoo .co.uk enlightened us with...
Why? Because I need to and if i had to explain why then i'd totally
confuse people!
Explaining things often shows that you're going about things the hard way or
shows complete errors in logic. Which is why we ask.

I looked at your example using Firefox and it didn't work.


Please quote what you are replying to.
And it works in my firefox.
What version are you using and explain "doesn't work". Did you get an error?
It isn't supposed to DO anything except fill in the form with the same values
you already chose. Look at the URL to see that the form was submitted. It's
not fancy. It's a simple example and needs fleshed out with url encoding and
whatnot for production use.

--
--
~kaeli~
Well, aren't we just a flipping ray of sunshine?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #5
cm*******@yahoo .co.uk wrote:
I have a form that has a select list.

A user chooses a value and the page refreshes showing the selected
value in the dropdown box.

So I want to use Javascript to get the selected query from the form.

I then want to pass it as a hidden field.

So for example the section of the page I'm interested in will look like
this.

<form action="asubmit page.htm" method="post">

<select name="ent" onchange="form. submit();"> ^^^^^^^^^^^^^^^ ^^^^^^^^^^
Don't. It is likely to make the form unusable without a pointing device
if client-side scripting is even supported. Users don't expect forms to
be submitted when they select a value of of its controls, they expect it
to be submitted when they activate a button control instead.
<option value="UK">UK</option>
<option selected value="USA">USA </option>
<option value="JAPAN">J APAN</option>
<option value="UK">UK</option>
</select>

I then want to take the selected value and submit it as a hidden field.

<form action="setpov. htm" method="post">
<input type="hidden" name="Entity" value=" this is where i want to fill
this with the selected value ">
</form>
<meta http-equiv="Content-Script-Type" content="text/javascript">
...
<script type="text/javascript">
function setValue(oForm, index, value);
{
var e;
if (oForm
&& (e = oForm.elements)
&& (e = e[index])
&& typeof e.value != "undefined" )
{
e.value = value;
}
}

function getSelectedValu e(oSelect)
{
if (oSelect)
{
if (oSelect.select edIndex >= 0)
{
return oSelect.options[oSelect.selecte dIndex];
}
else
{
return ""; // or any dummy value
}
}
}
</script>
...
<form action="setpov. htm" method="post">
<div>
<input type="hidden" name="Entity" value="">
<select name="ent"
onchange="setVa lue(this.form, 'Entity',
getSelectedValu e(this));">
[...]
</select>
<input type="submit" ...>
</div>
</form>
I take it javascript is the easiest way to do this.


*Client-side* JS is one way, however not the best one as it will not work
without client-side script support -- so you have to test server-side
anyway, why don't you just evaluate the value of the "ent" name-value pair
already submitted?
PointedEars
--
Set truthfulness above everything else.
When a man lies, he kills a part of the world.
-- Merlin (AFAIK)
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7298
by: Crystal | last post by:
Ok, I know this sounds weird, but it's really bugging me. I have a few list boxes on my form (basic pick a month, year, state stuff) and you can only choose one value. I need to be able to run a script to pick out those boxes and request the value and then response.write the value to a URL that I am creating. The script actually sends an email to me that contains a link to the form that the user filled in and populates the form with...
2
2929
by: Mike Button | last post by:
Hello all, I am really really desperate on what I should do, and I am asking for help from anyone in this newsgroup, here's the situation: I am creating a form that is being run on a server where there is no scripts allowed running (the software is from Opentext called Livelink)- therefore I need javascript to do the tasks listed below: 1. validate the form - this has been completed 2. pop up another window that will go ahead and...
5
8436
by: rjames.clarke | last post by:
I have the following. $result=mysql_query($sql); $nrows=mysql_num_rows($result); for ($i=0;$i<$nrows;$i++) { $row_array=mysql_fetch_row($result); echo "<form name='testform' action='ins_op.php' method='post'>"; lots of form stuff
3
10628
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems that are hard to find. The main problem I am having right now is that I have a report that is sorted by one of these lookup fields and it only displays the record's ID number. When I add the source table to the query it makes several records...
0
2249
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional assistance. I say additional because I've already had help which is greatly appreciated. I do try to take the time and understand the provided script in hopes on not having to trouble others on those. But here it goes...
8
3708
by: | last post by:
The problem lies here eval("document.TeeForm.amt.value(S+M)"); S and M suppose to add up and the total suppose to appear on the AMT field but it didn't. Any help? ============================ CODE ==============================================
1
1572
by: TopherB | last post by:
Hi, First let me say that my knowledge of HTML and Javascript is fairly limited. But I am stuck in a situation of trying to adapt a website's shopping cart to a new one. Here's the problem, the code contains thousands of 'Add to Cart' buttons that look almost identical to this HTML snippet spread across over hundred pages: <form> <p align="center"> <select name="package" size="1" style="width: 170" style="font-weight: 700"> <option...
3
2932
by: chifm | last post by:
Hi ALL, I dont know much about php, but have got a long form that i need to split into two pages, i want to have the inputs from the page 1 past to page 2 and all submitted via email at the end. I am really stock on this one. I have managed to split the form and I have used the php 'GET' and i could see the inputs at in url. Please any help will be most appreciated. Please find below the form below/ <form action="/form2.php"...
14
4349
by: confusedfusion | last post by:
Not sure how many form submissions that have been lost over the years before I started but the company has a contact form that the required fields when validation fails the error message is going into the URL string on a refresh of the form page. I am very green on CF and CFM files and have this code below; I need to help for the error messages to "pop up" in a new window or display on the body of the page so anyone filling out the form knows...
0
8197
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8589
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8287
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8443
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5548
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4136
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2573
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1438
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.