|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi there...
i've been fronting some idiotic problem in some script for a few days now. I know it's gotta be something simple but i just can't figure it out.. maybe ya'll guys could gimme some help here... Code:
<html>
<head>
<SCRIPT type="text/Javascript" LANGUAGE="JavaScript">
function content(nr) {
document.write("<html><body>");
document.write("<table width=400 border=2 align=center bordercolor=#428EC6 cellspacing=0 cellpadding=4>");
document.write("<tr bgcolor=#195F95><td width=10><center><font color=#FFFFFF size=2 face=arial><b>Id.</td>");
document.write("<td width=350><font color=#FFFFFF size=2 face=arial><center><b>Description</td>");
document.write("<td width=40><font color=#FFFFFF size=2 face=arial><center><b>Show</td></tr>");
for (i = 1; i <= nr; i++) {
document.writeln("<tr><td width=10 bgcolor=#384E84><font color=#FFFFFF size=2 face=arial><b>" + i + ".</td>");
document.writeln("<td width=350>bla bla... text... bla.. </td>");
document.writeln("<td width=40><img src=http://www.uky.edu/Housing/images/icons/smile.gif onclick=alert(i)></td>");
document.writeln("</tr>");
}
document.write("</table></body></html>");
}
content(5);
</script>
</head>
<body>
</body></html>
if you make a page out of that code and open it u get a table with 5 rows and the last column has some picture. when u click the picture a dialog pops and says 6 what i want is that if i click the picture on row 2, the alert types 2 or if i click the picture on row 5 it says 5 in the dialog and so on... i think it's all about passing the i variable to the alert function... in fact that's what i wanna do.... the code u seen is just a very very very simplified form of a huge table which contains columns such as ID, Image, Name, Description, Price, Order and what i really wanna do is to transmit de ID to a function that'll pull out the name and the price from an array or somthing and create a new document on the fly just as i click a button or something which'll be located in each cell of the last column... and the page contains a mail form... a lotta text fields, of which the first 2 would be the name and the price, and the rest of 'em.. name, adress and so on... ^ anyway.. this is some other thing... much too messy... if anyone has any ideea for fixing or improving the code i wrote... please feel free to reply |
|
#2
|
||||
|
||||
|
Please replace the deprecated tags with some CSS... it is more standards compliant, and is less for you to type in the long run...
in the case of your original question... I think this will work Code:
function content(nr)
{
document.write("<html><body>");
document.write("<table width=400 border=2 align=center bordercolor=#428EC6 cellspacing=0 cellpadding=4>");
document.write("<tr bgcolor=#195F95><td width=10><center><font color=#FFFFFF size=2 face=arial><b>Id.</b></font></center>");
document.write("<td width=350><font color=#FFFFFF size=2 face=arial><center><b>Description</b></font></center></td>");
document.write("<td width=40><font color=#FFFFFF size=2 face=arial><center><b>Show</b></font></center></td></tr>");
for (i = 1; i <= nr; i++)
{
document.writeln("<tr><td width=10 bgcolor=#384E84><font color=#FFFFFF size=2 face=arial><b>" + i + "</b></font></center>.</td>");
document.writeln("<td width=350>bla bla... text... bla.. </td>");
document.writeln("<td width=40><img src=http://www.uky.edu/Housing/images/icons/smile.gif onclick=alert(" + i + ")></td>");
document.writeln("</tr>");
}
document.write("</table></body></html>");
}
content(5);
Last edited by jsKid : June 5th, 2005 at 12:37 PM. |
|
#3
|
|||
|
|||
|
thank you soooo much!
that solved all my problems... God.. how such a minor technicality can mess up an entire project... |
|
#4
|
||||
|
||||
|
Quote:
__________________
|
|
#5
|
|||
|
|||
|
Quote:
whoaa.. didn't see that!... uuh.. wierd.. hey.. anyway.. i got some other thing now.. Code:
<html>
<head>
<SCRIPT type="text/Javascript" LANGUAGE="JavaScript">
function comanda(nr) {
var mytext = "this contains spaces";
document.open();
document.write("<html><body>");
document.write("<FORM name=e_form>Field: <INPUT type=text name=prod size=40 value=" + mytext + ">");
document.close();
}
</script>
</head>
<body>
<img src=http://www.nicks.ca/hardware/re-16-1.gif onclick=comanda(3)>
i was wondering if they're any issues about text fields i dunno about... the mytext variable doesn't appear in the text field corectly... it's only the first word... does any1 know why and whta can i do about it? ![]() |
|
#6
|
||||
|
||||
|
*sigh* Lazy programmers...
That's because you didn't put quotes around the value of the value attribute. Code:
document.write('<form name=e_form>Field: <input type="text" name="prod" size="40" value="' + mytext + '">');
You should be doing this server-side.
__________________
Spreading knowledge, one newbie at a time. Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around. Check out my blog. |
|
#7
|
|||
|
|||
uuuh dang... ur so much right... 10x a lot....in my imagination i couldn't picture quotes within other quotes, however later on i read some stuff about using them corectly and now this too, and.. it helped ![]() |
|
#8
|
|||
|
|||
|
and another one... hopefully the last:
i have this 2 textfields and 1 textarea in a form and i encounter a small dificulty at trying to pass the content of the fields into the textarea... i want it all to happen like this: user comes and types something in the first field, types something else in the second one and then he hits the Build button. and at that moment the content of the first field apears on the first line of the textarea and the content of the second field apears on the second line of the textarea. how plain can that be? ![]() Code:
<html>
<head>
<SCRIPT type="text/Javascript" LANGUAGE="JavaScript">
function comanda(nr) {
document.open();
document.write('<html><body background=bg.gif leftmargin=0 rightmargin=0 ');
document.write("bottommargin=0><table align=center width=400 border=1 cellspacing=0 cellpadding=5
bgcolor=#C1E3FF bordercolor=#002F56><tr><td><font color=#002F56 size=3 face=arial><b><center>Testing</td></tr>");
document.write('<tr><td><form name="myform">Name: <input type="text" name="thename" size="30" value=""><br>');
document.write('E-mail: <input type="text" name="email" size="30" value=""><br><hr color=#002F56>');
document.write('<input type="button" name="create" size="20" value="Build"
onclick="document.myform.thebody.value=document.myform.thename.value + '\n' +
document.myform.email.value"><hr color=#002F56><br>');
document.write('<TEXTAREA NAME="thebody" ROWS=8 COLS=40></TEXTAREA><hr color=#002F56>');
document.write("</td></tr></table>");
document.close();
}
comanda(4);
</script>
</head>
<body>
</body>
</html>
i was thinking that somewhere between the two variables i should add some "\n" thing but i just dunno how... i recieve errors if i do so.. |
|
#9
|
||||
|
||||
|
Quote:
what errors? have you tried escaping the -> \'\n\' |
|
#10
|
|||
|
|||
|
yea.. i know.. if i get that out it works.. but I NEED line breaking
i want the value of the first field stand on the first row and the other one on the second row... otherwise they'll both stick on the same row, furthermore, not a single space between them ![]() |
|
#11
|
||||
|
||||
|
You didn't even come close to saying yes or no...
It's clear what you want to do.. what's not clear, however, is what you've tried so far and what errors are you getting, if any. |
|
#12
|
|||
|
|||
|
well, if i used that + '\n' + i got an error on line 14, char 148 : Invalid character, and the page doesn't load at all
if i used double quotes + "\n" + , the page loaded but the button didn't do anything... error on line 23, char 1 : Syntax error i even tried adding a hidden field having the value "\n" and passing it's value in te textbox after the first fields' value.. it didn't work out... it did absolutely nothing.. i really don't know what to do anymore... though i think there's some problem with the quotes... as u could see i'm not that much of a real programmer, i'm weak probably even for a newbie so i'm kinna unsecure regarding my java spelling skills.. |
|
#13
|
||||
|
||||
|
okay.. much better that time...
try this... Code:
document.write('<input type="button" name="create" size="20" value="Build" onclick="document.myform.thebody.value=(document.myform.thename.value +'\n' + document.myform.email.value"><hr color="#002F56"><br>');
|
|
#14
|
||||
|
||||
|
Java != JavaScript
Why are you using JavaScript to write out that to the page? That code doesn't seem like it would ever output different HTML. Some people use broswers that do not have JavaScript enabled. There are two missing single quotes in this statement. I underlined them. Code:
document.write('<input type="button" name="create" size="20" value="Build"
onclick="document.myform.thebody.value=document.myform.thename.value' + '\n' +
'document.myform.email.value"><hr color=#002F56><br>');
|
|
#15
|
|||
|
|||
it's not working, guys... i tried this:Code:
document.write('<input type="button" name="create" size="20" value="Build"
onclick="document.myform.thebody.value=document.myform.thename.value' + '\n' +
'document.myform.email.value"><hr color=#002F56><br>');
and now it doesn't even show me the second value at all... try it yourself ![]() oh.. and the reason i wanna use a script is ... i don't know... it'd take me a lotta time to explain, the entire script is much more complicated... this is just a simple function meant to create this page on-the-fly... however the original version has more fields and it works with some global variables that many other function work with... |
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > newbie needing help with pathetic script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|