This is a discussion on "Javascript Hidden field problem..." within the JavaScript Forum section. This forum, and the thread "Javascript Hidden field problem... are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Javascript Hidden field problem...
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
Javascript Hidden field problem...
Hi,
I have the following piece of code: <input type="hidden" name="item_number"> But how can i add a value thats equal to a variable, something like: <input type="hidden" name="item_number" value = $var1> Where var1 is set previously using javascript. Thanks. |
|
|
|
#2
|
|||
|
|||
|
Re: Javascript Hidden field problem...
Give your field an 'id', it can be the same as the 'name', then use the code
|
|
#3
|
|||
|
|||
|
Re: Javascript Hidden field problem...
ive been trying for the last couple of days to get this working:
<script type="text/javascript"> document.write('<input type="hidden" name="item_name" value="'+displaytext1+'">'); </script> without success! ive tried alot of variations. it links into paypal, but paypal does not show the description. |
|
#4
|
|||
|
|||
|
Re: Javascript Hidden field problem...
I don't understand what you are trying to say in this post. My previous post answered the question you originally asked. |
|
#5
|
|||
|
|||
|
Re: Javascript Hidden field problem...
Sorry, im trying to feed the paypal shopping cart with a description, so nothing is displayed on my page, but is on the paypal page.
theres no problem hard coding the values, but i need to use a variable for the item description as its dynamic. Thanks. |
|
#6
|
|||
|
|||
|
Re: Javascript Hidden field problem...
Where is this description to be obtained from? |
|
#7
|
|||
|
|||
|
Re: Javascript Hidden field problem...
it is loaded on startup. a product id is passed in the URL and then this is decoded into a description - displaytext1.
|
|
#8
|
|||
|
|||
|
Re: Javascript Hidden field problem...
Ok. You need to process the file server side using php or some such. You can access variables passed as part of the url with the $_GET function.
|
|
#9
|
|||
|
|||
|
Re: Javascript Hidden field problem...
Ive already done steps 1 and 2, but was told I can use javascript to achieve the hidden field problem. I have no PHP experience, thats why I want to avoid this, my pag is purely html and javascript.
|
|
#10
|
|||
|
|||
|
Re: Javascript Hidden field problem...
To extract the id passed in the url using JavaScript you need to now the position of the id in the list of parameters that follow the '?' delimeter in the url. Then you can use;
Decode the id into a description and use the
|
|
#11
|
|||
|
|||
|
Re: Javascript Hidden field problem...
Thanks, i;ve now got the following:
<input type="hidden" name="business" id="email" value=""> <input type="hidden" name="item_name" id="descr" value=""> <input type="hidden" name="amount" id="num" value = ""> <script type="text/javascript"> document.getElementById("email").value = "email@hotmail.com"; document.getElementById("descr").value = displaytext1; document.getElementById("num").value = num4; </script> but only the email works, cos its hard coded, but still cant get the variables to work. |
|
#12
|
|||
|
|||
|
Re: Javascript Hidden field problem...
Show me a copy of the url from the browsers address bar and the code you are using to set the variables from the parameters passed in the url. |
|
#13
|
|||
|
|||
|
Re: Javascript Hidden field problem...
file:///D:/Details.htm?n1=33700&n2=mit&n3=18&n4=25&n5=4
<script type="text/javascript"> function GetVars( def ) { this._def_ = def; var query, queries = top.location.search.substring(1).split( /\&/ ); for ( var i=0; (query = queries[ i ]); i++ ) { query = query.split( /\=/ ); this[query[0]] = ( typeof query[1] == 'undefined' ) ? def : unescape(query[1]).replace( /\+/g, " " ); } } GetVars.prototype.exists = function( key ) { return ( typeof this[key] != 'undefined' ); } GetVars.prototype.assign = function( key ) { return ( this.exists( key ) ) ? this[key] : this._def_; } var displaytext1; var displaytext2; var _GET = new GetVars( '' ); var num1 = _GET.assign( 'n1' ); var num2 = _GET.assign( 'n2' ); var num3 = _GET.assign( 'n3' ); var num4 = _GET.assign( 'n4' ); var num5 = _GET.assign( 'n5' ); switch (num1) { case '33700': displaytext1='Test'; . . . Is this ok? I know the assignments at the bottom definitely work. Getvars is called 'onload'. |
|
#14
|
|||
|
|||
|
Re: Javascript Hidden field problem...
With this piece of code
This is not what is happening. You are only picking up the first parameter, substring(1), therefore you are trying to split 'n1=33700'. I also think the rest of your code is over complicated for what you are trying to do. Golden rule - Keep It Simple. |
|
#15
|
|||
|
|||
|
Re: Javascript Hidden field problem...
after this code, ive 'writeln' the variables to the page and they are all correct, ie theres no 'n1=' within any of the variables, they contain the text i need.
its just the getelementbyid, im not sure whats wrong with the variable assignemnt im trying to do, been at this since yesterday! |
![]() |
| Tags |
| javascript, hidden, field, problem |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [SOLVED] Text field & list menu size problem | longstand | Web Page Design | 2 | Nov 1st, 2007 12:38 |
| Need javascript to set input field value field | jdadwilson | JavaScript Forum | 3 | May 9th, 2007 04:47 |
| Display Problem: Form-->Legend field in Firefox | SuperGrover1981 | Web Page Design | 2 | Sep 5th, 2006 18:05 |
| Hidden layers using CSS and JavaScript | blis102 | Web Page Design | 1 | Jun 29th, 2006 21:17 |
| Odd input field not displaying problem | hankhill | Classic ASP | 1 | Jun 26th, 2006 23:11 |