Front Office Football Central

Front Office Football Central (https://forums.operationsports.com/fofc//index.php)
-   Off Topic (https://forums.operationsports.com/fofc//forumdisplay.php?f=6)
-   -   Basic javascript help (https://forums.operationsports.com/fofc//showthread.php?t=80855)

Rizon 03-08-2011 10:18 PM

Basic javascript help
 
I'm trying to get this code to output first and last name into the 3rd box. It's not working and I'm not sure why. Any help?

*I can't figure out how to put code in here, so I just attached the file.

3ric 03-09-2011 04:28 AM

I'm not seeing any attachment?

Ronnie Dobbs2 03-09-2011 06:31 AM

Code:

I think it's (bracket)code(bracket)CODE GOES HERE(bracket)/code(bracket).

Replace the (bracket) with [ and ] obv.

But yeah, nothing attached on my end either.

Rizon 03-09-2011 10:02 AM

Oops. Here it is

HTML Code:

<html>
<head>
<title>
COMSC 100 WorkbookAssignment 4
</title>
<script>
function GO()
{

// declare a variable
var firstName;

// get variable's value
firstName = document.getElementById("firstName").value;

// insert the value of firstName
insert(firstName)

// declare a variable
var lastName;

// get variable's value
lastName = document.getElementById("lastName").value;

// insert the value of lastName
insert(lastName)

// declare a variable
var fullName;

// get variable's value
fullName = firstName.value + " " + lastName;
}
</script>

</head>
<body>
Instructions:
Type your first and last name, then click GO
and a greeting will appear.

Input values:

First Name: <input id=\"firstName\">
Last Name: <input id=\"lastName\">
<input type=\"submit\" value=\"GO\" onclick=\"GO()\">

Output value:
Happy New Year, <input type=\"fullName\">

</body>
</html>[html]

[/html]

Rizon 03-09-2011 10:03 AM

Trying to get it to look like this, where the you enter your first and last name, hit GO and it puts your full name in the last box.



<br /> COMSC 100 WorkbookAssignment 4<br />




Instructions:

Type your first and last name, then click GO

and a greeting will appear.



Input values:


First Name:

Last Name:





Output value:

Happy New Year,




Coffee Warlord 03-09-2011 10:26 AM

Code:

function popFull()
{
    form1.fullname.value = form1.firstName.value + " " + form1.lastName.value;
}


That's all you need. Call popFull as an onClick in the 'go' button, done.

HTML Code:


<form name='form1'>
<input type='text' name='firstName'>
<input type='text' name='lastName'>

<input type='text' name='fullname'>

<input type='button' value='Go' onClick=\"popFull();\">


Rizon 03-09-2011 12:23 PM

Thanks CW. I'm totally code illiterate, so I'm not sure what to replace to the old code or where to add your code or both? We're supposed to be learning this in class, but the teacher gives the same story about cake and we don't seem to be learning any JS or HTML.

Coffee Warlord 03-09-2011 12:32 PM

What I gave you is basically the completed everything. You only need that one line of javascript to accomplish what you want, and I included the actual necessary portion of the html. You'll need to add like the html/body/etc tags and such, but the meat is all there.

Ronnie Dobbs2 03-09-2011 03:23 PM

If you wanted to do it with your original code (which might be more appropriate for a CSCI 1 assignment) I would ask you to look at the insert function. You are saying WHAT to insert, but not including WHERE.
http://www.prototypejs.org/api/element/insert

Coffee Warlord 03-09-2011 03:50 PM

Learn it the efficient way, dammit. Don't learn bloated programming techniques. :)


All times are GMT -5. The time now is 07:34 PM.

Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.