JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 5th, 2005, 11:53 AM
r41nman r41nman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 15 r41nman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 40 sec
Reputation Power: 0
Red face newbie needing help with pathetic script

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

Reply With Quote
  #2  
Old June 5th, 2005, 12:25 PM
jsKid's Avatar
jsKid jsKid is offline
Application is what Divides Us
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2002
Location: Titusville, FL
Posts: 2,169 jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 13 h 31 m 44 sec
Reputation Power: 53
Send a message via AIM to jsKid Send a message via MSN to jsKid
MySpace
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);
__________________
Download [ Fx | Op ] Validate [ Markup | Css ]

Last edited by jsKid : June 5th, 2005 at 12:37 PM.

Reply With Quote
  #3  
Old June 5th, 2005, 03:19 PM
r41nman r41nman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 15 r41nman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 40 sec
Reputation Power: 0
thank you soooo much!

that solved all my problems... God.. how such a minor technicality can mess up an entire project...

Reply With Quote
  #4  
Old June 5th, 2005, 09:15 PM
Markisdee's Avatar
Markisdee Markisdee is offline
****ing running
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2003
Location: Not typing in a location. Damn.
Posts: 2,141 Markisdee User rank is Major (30000 - 40000 Reputation Level)Markisdee User rank is Major (30000 - 40000 Reputation Level)Markisdee User rank is Major (30000 - 40000 Reputation Level)Markisdee User rank is Major (30000 - 40000 Reputation Level)Markisdee User rank is Major (30000 - 40000 Reputation Level)Markisdee User rank is Major (30000 - 40000 Reputation Level)Markisdee User rank is Major (30000 - 40000 Reputation Level)Markisdee User rank is Major (30000 - 40000 Reputation Level)Markisdee User rank is Major (30000 - 40000 Reputation Level)Markisdee User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 5 h 38 m 28 sec
Reputation Power: 351
Send a message via AIM to Markisdee
Quote:
Time spent in forums: < 1 sec
Wow, you post fast.
__________________

Reply With Quote
  #5  
Old June 7th, 2005, 04:09 PM
r41nman r41nman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 15 r41nman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 40 sec
Reputation Power: 0
Talking

Quote:
Originally Posted by Markisdee
Wow, you post fast.


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?

Reply With Quote
  #6  
Old June 7th, 2005, 05:32 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 23rd Plane (16000 - 16499 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 16,407 Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Months 1 Day 14 h 19 m 23 sec
Reputation Power: 1780
*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.

Reply With Quote
  #7  
Old June 8th, 2005, 07:14 AM
r41nman r41nman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 15 r41nman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 40 sec
Reputation Power: 0
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

Reply With Quote
  #8  
Old June 11th, 2005, 07:39 AM
r41nman r41nman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 15 r41nman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 40 sec
Reputation Power: 0
Exclamation Textarea

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..

Reply With Quote
  #9  
Old June 11th, 2005, 01:46 PM
jsKid's Avatar
jsKid jsKid is offline
Application is what Divides Us
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2002
Location: Titusville, FL
Posts: 2,169 jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 13 h 31 m 44 sec
Reputation Power: 53
Send a message via AIM to jsKid Send a message via MSN to jsKid
MySpace
Quote:
Originally Posted by r41nmain
i recieve errors if i do so

what errors? have you tried escaping the -> \'\n\'

Reply With Quote
  #10  
Old June 11th, 2005, 01:55 PM
r41nman r41nman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 15 r41nman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 40 sec
Reputation Power: 0
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

Reply With Quote
  #11  
Old June 11th, 2005, 01:58 PM
jsKid's Avatar
jsKid jsKid is offline
Application is what Divides Us
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2002
Location: Titusville, FL
Posts: 2,169 jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 13 h 31 m 44 sec
Reputation Power: 53
Send a message via AIM to jsKid Send a message via MSN to jsKid
MySpace
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.

Reply With Quote
  #12  
Old June 11th, 2005, 02:23 PM
r41nman r41nman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 15 r41nman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 40 sec
Reputation Power: 0
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..

Reply With Quote
  #13  
Old June 11th, 2005, 02:30 PM
jsKid's Avatar
jsKid jsKid is offline
Application is what Divides Us
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2002
Location: Titusville, FL
Posts: 2,169 jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 13 h 31 m 44 sec
Reputation Power: 53
Send a message via AIM to jsKid Send a message via MSN to jsKid
MySpace
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>');

Reply With Quote
  #14  
Old June 11th, 2005, 02:33 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 23rd Plane (16000 - 16499 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 16,407 Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Months 1 Day 14 h 19 m 23 sec
Reputation Power: 1780
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>');
Comments on this post
jsKid agrees: I had a ( instead of a '... but you topped it off..

Reply With Quote
  #15  
Old June 11th, 2005, 03:55 PM
r41nman r41nman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 15 r41nman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 40 sec
Reputation Power: 0
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...

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > newbie needing help with pathetic script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT