It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Problem with a function

Re: Problem with a function

Postby Logician on Thu Sep 27, 2007 12:16 pm

wavelink wrote:I'm trying to write a function that will when toggle between to form elements when an event is called. Here's a sample of what I'm doing.

<html>
<head>
<script type="text/javascript">
function tuggle()
{
if (document.getElementById("numbers").disabled="true")
{
document.getElementById("fruit").disabled="false";
}
else
{
document.getElementById("numbers").disabled="false";
}
}

</script>


Code: Select all
function tuggle()
{
var state=document.getElementById("numbers").disabled^=true;
document.getElementById("fruits").disabled=!state;
}
Logician
 
Posts: 20
Joined: Tue Jun 12, 2007 3:43 am
Location: U.K.

Postby wavelink on Thu Sep 27, 2007 3:34 pm

Yes, Yes, Yes. I finnally got it.
Thaks guys. I had to preset one element as disabled, but it works. Checke it out.

<html>

<head>

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


function makedisable()
{
document.getElementById("numbers").disabled=true;
}

function toggle(){
{
eval(document.getElementById("fruits"));
eval(document.getElementById("fruits").disabled);
document.getElementById("fruits").disabled=!document.getElementById("fruits").disabled;
}
{
eval(document.getElementById("numbers"));
eval(document.getElementById("numbers").disabled);
document.getElementById("numbers").disabled=!document.getElementById("numbers").disabled;
}
}

</script>


</head>

<body onload="makedisable()">

<form>

<select id="fruits">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>

&nbsp; &nbsp;

<select id="numbers">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>

<br><br>

<input type="button" onclick="toggle()"value="Toggle">

&nbsp; &nbsp;

</form>

</body>

</html>
wavelink
 
Posts: 8
Joined: Mon Sep 24, 2007 1:17 am

Postby Logician on Thu Sep 27, 2007 4:33 pm

wavelink wrote:
Code: Select all
    eval(document.getElementById("fruits"));
    eval(document.getElementById("fruits").disabled);
This code has no effect.
Logician
 
Posts: 20
Joined: Tue Jun 12, 2007 3:43 am
Location: U.K.

Postby wavelink on Thu Sep 27, 2007 5:25 pm

You are right!
I removed it from the code and it works fine.

Thanks again.
wavelink
 
Posts: 8
Joined: Mon Sep 24, 2007 1:17 am

Postby wavelink on Fri Sep 28, 2007 3:14 am

The function is working great, however now I'm faced with another issue. Somehow another larger function is still reading the disabled elements. I can think of two ways around this without altering the larger function, which is not an option anyway. One is to build another function that will block the larger function from reading any disabled elements. The other is not to block the larger function at all, but to fiddle with the toggle function so that it will ad a "selected" empty option to the pull down list to be read. Thus posting empty data along with the real data.

PS: I thought that disabled elements would be ignored in a form. It looks like that's not the case.
wavelink
 
Posts: 8
Joined: Mon Sep 24, 2007 1:17 am

Postby matt_raleigh on Fri Sep 28, 2007 1:11 pm

If I were you then I would build another function that will block the larger function from reading any disabled elements.

I think it is a bad idea to send empty data, because then you will have to create something on the server side to parse out the empty data, which is more overhead on the server.
User avatar
matt_raleigh
 
Posts: 15
Joined: Thu Sep 20, 2007 6:45 pm

Previous

Who is online

Users browsing this forum: No registered users and 6 guests