...

View Full Version : very newbie question



hanna975
04-24-2004, 03:00 AM
:confused:
Since there are alot of people who know their stuff here, got a javascript question.

I'm a complete newb to javascript and have an assignment for class(Intro to web design) I can't fiqure out for the life of me.

I need to create 2 text boxes and 2 buttoms that perform certain tasks in javascript.

The alert button I fiqured out(Display input from textbox1 in an alert window).

The switch button, I'm stuck on. I need to take the input from textbox1 and place in textbox2 when clicked. I declared the variable "switch" to use for that function. Here is the code I have so far. The question marks are where I'm stuck. I don't need this done for me, but help is appreciated.

Thanks in advance on this one.

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<title>Brad Hanna's lab4/19</title>

<script type="text/javascript" language="javascript">

var switch;
switch = (stuff1);
function helloalert(input)
{
window.alert(input)
}
</script>

</head>

<body>

<h1>Lab 4/19</h1>

<p>Type anything in the first field</p>

<form>
<input name="stuff1" type="text" />
<input name="stuff2" type="text" /><br/>
<input name="alert" type="button" value="Alert"
onclick="helloalert(form.stuff1.value)" />
<input name="switch" type="button" value"Switch"
onclick=?????? />
</form>



</body>

</html>

Philip M
04-24-2004, 08:48 AM
'switch' is a reserved word or keyword in JavaScript, that is part of the language syntax which is not available as an identifier name for a variable or function.

Also,it is not a very good idea to give elements or variables the same NAMEs as their VALUEs, as it can cause confusion. e.g. Name = "Alert" Value = "Alert", or var message = "message"

hanna975
04-24-2004, 03:17 PM
Thanks,
Can you tell I'm new at this. We're two days into javascript and I'm already getting stuck. Glad the semester is almost over. I can work on this more on my free time.

squirellplaying
04-24-2004, 05:03 PM
When you switch two things you will need to save one in a variable.


<html>
<head>
<script>
function sSwitch(txt1,txt2){
var saveMe = txt1.value
txt1.value=txt2.value
txt2.value=saveMe
}

</script>
</head>
<body>

<input type = "text" id="i1" /><br />
<input type= "text" id="i2" /><br />
<input type="button" onclick="sSwitch(document.getElementById('i1'),document.getElementById('i2'))" />
</body>


</html>

hanna975
04-25-2004, 05:55 PM
Thanks squirellplaying,

I was having problems calling my variables :thumbsup:
I'll have to get my c++ mentality back :eek:
I love these forums, everyone is willing to help those in
need. Here's a good one if your into pocketpc's. They've
helped me with things like creating themes to setting
up and securing my wireless network.
They're mostly into the Dell Axim's but all are welcome.

WWW.AXIMSITE.COM

JPM
04-25-2004, 10:29 PM
You have Javascript at school in the US?!

...***Dreaming***

squirellplaying
04-25-2004, 10:36 PM
Me too. I have (x)html/css, javascript, java, asp, mysql, and C++(It's one of the C, not sure which one.). That's just in highschool :).

hanna975
04-26-2004, 12:07 AM
I'm in college and an adult student at that. When I was in highschool, we were lucky to have computers at all. I'm not even sure what operating system they used.(I didn't do well with computers back then). The monitors were even those black and green screens. Monochrome, I think. This was back in the late 80's where the internet was just a year or two old. I'm so glad that technology has made the advances it has made. It's kind of hard to believe we've come this far. :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum