Jump to content

Archived

This topic is now archived and is closed to further replies.

coldkill

JS Problem ::SOLVED::

Recommended Posts

Hey folks,
I have a slight problem with one of my JS scripts. It doesn't work for one ¬¬.

It is supposed to change the action value of a form and is called from the onClick HTML function.

Here is a the script:
[code]
function Action()
{
var form = document.getElementById(\'editform\');
var checkbox = document.getElementById(\'preview\');

if( checkbox.checked == true )
{
form.action = "'.DOMAIN.'index.php?module=admin&id=news_mod&preview"
}
else
{
form.action = "'.DOMAIN.'source/action/exec.php"
}
}[/code]
It's echoed from a PHP script and DOMAIN is changed for the current working directory of the site.

Thanks in advance,
Mike

Share this post


Link to post
Share on other sites
for the a = bool ? true_val : false_val

all I see is a = val ? true_val : false_val... don't you need to test that first val against something before something is returned?

Share this post


Link to post
Share on other sites
When it is called it is alternated I belive. Although I will try an if statement instead of the above.

::EDIT::
Updated the code above. Still doesn't work.

Share this post


Link to post
Share on other sites
is it possible to see your form code as well? thanks.

Now does the JS script not work because there is something wrong syntactically?
Or does the function get called but it just doesn't do what you expect it to do?

Make sense?

Share this post


Link to post
Share on other sites
Yeah, it is called but it doesn't do anything when it's called. It's called by the checkbox called "preview" with the onclick [xHTML] function.

Heres the form code. I took out some buttons from this example which arn't useful to solving this problem.

Thanks,
Cold

[code]
<form action="'.DOMAIN.'source/action/exec.php" mothod="post" name="editform" id="editform" enctype="application/x-www-form-urlencoded">
<table cellpadding="0" border="0" width="100%">
<tr>
<td>Title:</td>
        <td><input name="title" type="text" class="inputhelp"></td>
</tr>
<tr>
<td></td>
<td><input id="use" type="text" value="Help" readonly="true" class="inputhelp" /></td>
</tr>
<tr>
<td>Text:</td>
<td><textarea name="post" class="inputarea"></textarea></td>
</tr>
<tr>
<td>Preview news post?</td>
<td><input name="preview" id="preview" type="checkbox" onclick="javascript:Action()" value="checked"></td>
</tr>
<tr>
        <td><input name="type" type="hidden" value="news" /></td>
        <td><input name="submit" type="submit" value="Submit" class="submitbutton"/></td>
</tr>
</table>
</form>[/code]

Share this post


Link to post
Share on other sites
method is spelled wrong in your form.  I tested your code and changing mothod to method seemed to do the trick

Share this post


Link to post
Share on other sites
Yay! Works now. Can't believe it was a spelling mistake ¬¬.

Thanks for the help.
Cold

[b]::SOLVED::[/b]

Share this post


Link to post
Share on other sites
No problem ... glad to help :)... Sometimes it takes another person to look at your code and point stuff like that out to you... I've done that so much in my 8 years as a programmer :).

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.