473,387 Members | 1,295 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Access field data in a <script>-tag?

Hi!

How to access the html-document's field-data from within a <script>-tag?
I am trying to write a dynamic table (in a html-document) that is supposed to contain data that is stored in a <hidden> field i the document. Is it possible to pass the field data from the document to the javascript function that is called inside the <script>-tag?

Regards,
Per M
Aug 30 '07 #1
5 1635
epots9
1,351 Expert 1GB
Hi buster89 welcome to TSDN,

inside your javascript you would want to use:
Expand|Select|Wrap|Line Numbers
  1. var value = document.getElementById("id").value;
  2.  
good luck
Aug 30 '07 #2
Hi!
I tried that, but with no success...

This is my code:

The form:
Expand|Select|Wrap|Line Numbers
  1. .
  2. .
  3. .
  4. <tr class = "formTr">
  5. <td class = "textBold"><input name="INtext_1" value="" class="text" size="120"></td>
  6. <td class = "textBold" align = "right"><input name="INantal_1" value="" class="text" size=4></td>
  7. <td class = "textBold" align = "right"><input name="INpris_1" value="" class="text" size=4></td>
  8. <td class = "textBold" align = "right">&nbsp;</td>
  9. </tr>
  10.  
  11. <script>skriv()</script>
  12.  
  13. </table>
  14. .
  15. .
  16. .
  17. <input name="inmatat_1" value=";text:z;antal:1;pris:1;summa:1~;text:z;antal:1;pris:3;summa:3~;text:aa;antal:2;pris:3;summa:6~;text:a;antal:45;pris:65;summa:2925~;text:zzzzzzzzzzzzz;antal:99;pris:99;summa:9801~" id="nr1" TYPE="HIDDEN">
  18. .
  19. .
  20. .
  21.  
The javascript:
Expand|Select|Wrap|Line Numbers
  1. function skriv(){
  2. var value = document.getElementById("nr1").value;
  3. alert(value)
  4. }
  5.  
Any ideas?

Regards,
Per M
Aug 30 '07 #3
gits
5,390 Expert Mod 4TB
call the skriv()-function in onload of your html-body ... document.getElementById() needs a fully loaded dom to work ...

kind regards
Aug 30 '07 #4
pbmods
5,821 Expert 4TB
Heya, Per.

Note in your code:
Expand|Select|Wrap|Line Numbers
  1. <script>skriv()</script>
  2.  
  3. </table>
  4. .
  5. .
  6. .
  7. <input name="inmatat_1" value=";text:z;antal:1;pris:1;summa:1~;text:z;antal:1;pri  s:3;summa:3~;text:aa;antal:2;pris:3;summa:6~;text:  a;antal:45;pris:65;summa:2925~;text:zzzzzzzzzzzzz;  antal:99;pris:99;summa:9801~" id="nr1" TYPE="HIDDEN">
  8. .
  9. .
  10. .
  11.  
You're calling skrik() before the nr1 input has been created! The browser evaluates the code from top to bottom.

Move your script block after the input in your code, or put the skrik() call in the body's onload attribute (as Gits suggested) to solve this problem.
Aug 30 '07 #5
Yes!
Thank you so much! It did totally slipped my mind that the hidden field containing the data must be located at the top of the form because it does not extist until it has been written to the screen. I thougt tthe problem was the encapsulated script in the script tag.
(Now I am going to skip all the html in the form, and just use one tag that produces the whole form: <script>printForm()</script>.)

Thanks so much for your help - you really saved my day (... and my weekend too)

:)
Aug 31 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Madhav | last post by:
I have the following statements in my script. ---------------------------------------------------------- textToWrite = "<HTML> \n" + "<HEAD> \n" + "<TITLE>Calendar</TITLE> \n" + "<SCRIPT...
30
by: Toni Mcintyre | last post by:
i'm having 2 problems with the http://validator.w3.org 1. if i have: <meta http-equiv="Content-Script-Type" content="text/javascript"> then why do i need <script type=text/javascript>...
10
by: Blue® | last post by:
I would like to call the content of content.htm (containing only HTML codes) into index.htm. This is usually done by renaming index.htm to index.shtml and use this tag: <!--#include...
1
by: JMMB | last post by:
The <script> tags work in a htm page, but when I convert it to .aspx page, it stops working? I get a IE script error. What might be the mistake here? thanks, <HTML> <HEAD> <TITLE> Teste...
2
by: Jeffrey T. | last post by:
I had some JavaScript functions defined in the <SCRIPT> section at the top of an aspx page (tested fine there). I then moved the JavaScript functions to their own separate file and then...
5
by: batham | last post by:
Hi Gurus, How can I execute a script during runtime. Here is my code, so how do I execute the new script during runtime which should be a part of the 'topDiv'. Thanks Help is appreciated. -...
9
by: sam.s.kong | last post by:
Hello! I have a JavaScript code like the following. <script> var s = "</script>"; ....
2
by: -Karl | last post by:
Couls someone please advise me on this error. What I am trying to do is be able to convert an XML document into arrays. I read that the subs & functions have to be in <scripttags. Thanks! ...
0
by: Chetana | last post by:
Hi, Following code is working in FireFox, but it is not working in IE. Response.Write("<script>window.opener.location.href='ViewDepartment.aspx';</ script>"); So Please Let me know if...
3
by: joe | last post by:
Is it OK to have multiple: <script type="text/javascript" src="funcs1.js"></script> <script type="text/javascript" src="funcs2.js"></script> <script type="text/javascript"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.