Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unable to get values from form !?!

Status
Not open for further replies.

nykotai

Programmer
Oct 7, 2003
10
0
0
US
Hi,

I m having some issues with extracting values out of a form.
Here is some debug code snippet below. When executing the page i get an undefined value on the alert box instead of the value that i entered on the form.

<form action="test.aspx" name="bilan_insert" method="get" >
<table width=573 border=0>
<tr>
<td>
<table ID="Table2" Width="287px" bgcolor="Gray" CellPadding="1" CellSpacing="1">
<tr>

<td width="65%" >Charges Immobilises</td>
<td ID="TableCell4" bgcolor="White">


<!---That is where the error occurs when executing the onblur-->

<input type="text" value="0" name="actif_1" onblur="alert(((document.bilan_insert.actif_1.value)))" size="12" maxlength="12">


Am i missing something to the document.bilan_insert.actif_1.value??? It seemed to me that the syntax was correct
 
I'm not really sure why you have 3 sets of parens, so first I'd chop those down to 1 set. Second, you don't really need to access the element that way, since it is referencing it's own value you can use this instead:
Code:
<input type="text" value="0" name="actif_1" onblur="alert([!]this[/!].value)" size="12" maxlength="12">

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
Well the code above serves to debug.
I m using document.bilan_insert.actif_1.value instead of this.value because i m trying to get values from a form passed on to a javascript function.

I have a form where u can enter some numbers and i want to be able to calculate certains fields based on previous entries, so i have a function that take input from different fields and add them and using the onblur i m trying to pass those aggregate values back to the form but i cant even get the values out of the form at this point of time.

The error that im getting is document.bilan_insert.actif_1 is null or not an object
 
what is with this site? why do people ask a question about errors in their code, and then post code that ISN'T their code?

i don't get it!



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
???? Dude chill out ... As i mentioned the code above is for debuggig purpose and if it works in the debugging code should work in the final app because it is the same context
 
I call BS. After I provided your "debugging" code with the REQUIRED end tags for your TDs, TRs, TABLEs and FORM, this worked exactly as expected.

Code:
	<form action="test.aspx" name="bilan_insert" method="get">
		<table width="573" border="0">
			<tr>
				<td>
					<table id="Table2" width="287px" bgcolor="Gray" cellpadding="1" cellspacing="1">
						<tr>
							<td width="65%">	Charges Immobilises
							</td>
							<td id="TableCell4" bgcolor="White">	<!---That is where the error occurs when executing the onblur-->								
								<input type="text" value="0" name="actif_1" onblur="alert(((document.bilan_insert.actif_1.value)))" size="12" maxlength="12">
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </form>



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
did you do as cory asked and confirmed the input element resides inside the form? document.blah.blah2 is not standard practice for referencing elements. Use the forms and elements collections instead:
Code:
document.forms["formname"].elements["elementname"]
or if the input element can have a unique id, use document.getElementById instead - as it is the preferred method.

Finally, cory has a very valid point about your question. It is exponentially more difficult to solve your problem if you do not present the problematic code. Often times trying to present a stripped-down version of what is wrong leads to things being left out that are relevant to the problem - or to syntax errors from mistyping that don't exist in the original code. Show us what we need to see, not what you think we need to see.

Out of curiosity who found nykotai's questions helpful enough to award a star? I'm confused. [ponder]

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top