471,311 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,311 software developers and data experts.

can't get simple confirm() to work

LRW
Having a problem getting a onSubmit function to work, to where it popsup a
confirmation depending on which radiobutton is selected.
Here's what I have:

function checkdel() {
if (document.getElementById["rd_del[]"].value=='1') {
confirm('Are you sure you want to delete this file?');
}
}
......
<FORM NAME="form1" ID="form1" action="index.php?procid=5" method="POST"
enctype="application/x-www-form-urlencoded" target="_self" onSubmit="return
checkdel();">
<div align="left" class="headerLG">Do you want to delete this article?
&nbsp;<input name="rb_del" id="rb_del" type="radio" value="0" checked>No
<input name="rb_del" id="rb_del" type="radio" value="1"> Yes </div><p />
I've tried:
document.getElementById["rd_del"].value=='1'
document.getElementById["rd_del[1]"].checked==true

I've looked up DOM and looked for examples, and from what I can see, I have
it formatted correctly.
I've also tried syntax that's put the 'form1' in the line above, but I just
can't make it work.
What am I missing? Just a clue would help!

Thanks for any replies,
Liam
Jul 23 '05 #1
13 2104
LRW wrote:
Having a problem getting a onSubmit function to work, to where it popsup a confirmation depending on which radiobutton is selected.
Here's what I have:

function checkdel() {
if (document.getElementById["rd_del[]"].value=='1') {
confirm('Are you sure you want to delete this file?');
}
}
.....
<FORM NAME="form1" ID="form1" action="index.php?procid=5" method="POST" enctype="application/x-www-form-urlencoded" target="_self" onSubmit="return checkdel();">
<div align="left" class="headerLG">Do you want to delete this article? &nbsp;<input name="rb_del" id="rb_del" type="radio" value="0" checked>No <input name="rb_del" id="rb_del" type="radio" value="1"> Yes </div><p />

I've tried:
document.getElementById["rd_del"].value=='1'
document.getElementById["rd_del[1]"].checked==true

I've looked up DOM and looked for examples, and from what I can see, I have it formatted correctly.
I've also tried syntax that's put the 'form1' in the line above, but I just can't make it work.
What am I missing? Just a clue would help!

Thanks for any replies,
Liam

Where would you like to start?

It's document.getElementById() - a function. Parentheses; square
brackets are for object/array references.

This:

"rd_del[1]"

....while sort of legitimate (some disagreement on this point) is only
for passing a form name that includes square brackets in its name,
usually to make it an array on the php side. It has no intrinsic
meaning in javascript: 'real' square brackets in JavaScript are not
string characters, but language operators - so you appear to be
confusing php array references with JS ones.

..value=='1'

Not much point in checking the value of a radio button, it pretty much
will be whatever you set it to. It's the .checked property, indicating
you-know-what, that you're looking for. OK, you suspected that. To
reference the second ("yes") button by name:

rb_del[1]

....as JS counts from one. Note that this is an actual array reference
and not a string.

You also didn't return the return value of the confirm() box, rendering
it pretty useless. OK, enough. Might as well use an id (which must be
unique).

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<script type="text/javascript">
//<![CDATA[

function checkdel()
{
if (document.getElementById('rb_del_yes').checked)
return confirm('Are you sure you want to delete this file?');
else return false;
}

//]]>
</script>
</head>
<body>
<form ID="form1" action="index.php?procid=5" method="POST"
target="_self"
enctype="application/x-www-form-urlencoded" onsubmit="return
checkdel()">
<div align="left" class="headerLG">Do you want to delete this article?
&nbsp;<input name="rb_del" id="rb_del_no" type="radio" value="0"
checked="checked">No
<input name="rb_del" id="rb_del_yes" type="radio" value="1">Yes</div><p
/>
<input type="submit" value="delete article" />
</form>
</body>
</html>

[cleaned up a few other items]

Jul 23 '05 #2
LRW wrote:
Having a problem getting a onSubmit function to work, to where it popsup a confirmation depending on which radiobutton is selected.
Here's what I have:

function checkdel() {
if (document.getElementById["rd_del[]"].value=='1') {
confirm('Are you sure you want to delete this file?');
}
}
.....
<FORM NAME="form1" ID="form1" action="index.php?procid=5" method="POST" enctype="application/x-www-form-urlencoded" target="_self" onSubmit="return checkdel();">
<div align="left" class="headerLG">Do you want to delete this article? &nbsp;<input name="rb_del" id="rb_del" type="radio" value="0" checked>No <input name="rb_del" id="rb_del" type="radio" value="1"> Yes </div><p />

I've tried:
document.getElementById["rd_del"].value=='1'
document.getElementById["rd_del[1]"].checked==true

I've looked up DOM and looked for examples, and from what I can see, I have it formatted correctly.
I've also tried syntax that's put the 'form1' in the line above, but I just can't make it work.
What am I missing? Just a clue would help!

Thanks for any replies,
Liam

Where would you like to start?

It's document.getElementById() - a function. Parentheses; square
brackets are for object/array references.

This:

"rd_del[1]"

....while sort of legitimate (some disagreement on this point) is only
for passing a form name that includes square brackets in its name,
usually to make it an array on the php side. It has no intrinsic
meaning in javascript: 'real' square brackets in JavaScript are not
string characters, but language operators - so you appear to be
confusing php array references with JS ones.

..value=='1'

Not much point in checking the value of a radio button, it pretty much
will be whatever you set it to. It's the .checked property, indicating
you-know-what, that you're looking for. OK, you suspected that. To
reference the second ("yes") button by name:

rb_del[1]

....as JS counts from one. Note that this is an actual array reference
and not a string.

You also didn't return the return value of the confirm() box, rendering
it pretty useless. OK, enough. Might as well use an id (which must be
unique).

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<script type="text/javascript">
//<![CDATA[

function checkdel()
{
if (document.getElementById('rb_del_yes').checked)
return confirm('Are you sure you want to delete this file?');
else return false;
}

//]]>
</script>
</head>
<body>
<form ID="form1" action="index.php?procid=5" method="POST"
target="_self"
enctype="application/x-www-form-urlencoded" onsubmit="return
checkdel()">
<div align="left" class="headerLG">Do you want to delete this article?
&nbsp;<input name="rb_del" id="rb_del_no" type="radio" value="0"
checked="checked">No
<input name="rb_del" id="rb_del_yes" type="radio" value="1">Yes</div><p
/>
<input type="submit" value="delete article" />
</form>
</body>
</html>

[cleaned up a few other items]

Jul 23 '05 #3
.....and thanks to goddamgooglegroups for the double post !!!

Jul 23 '05 #4

RobB wrote:
LRW wrote:
Having a problem getting a onSubmit function to work, to where it popsup a
confirmation depending on which radiobutton is selected.

function checkdel()
{
if (document.getElementById('rb_del_yes').checked)
return confirm('Are you sure you want to delete this file?');
else return false;
}

//]]>
</script>
</head>
<body>
<form ID="form1" action="index.php?procid=5" method="POST"
target="_self"
enctype="application/x-www-form-urlencoded" onsubmit="return
checkdel()">
<div align="left" class="headerLG">Do you want to delete this article? &nbsp;<input name="rb_del" id="rb_del_no" type="radio" value="0"
checked="checked">No
<input name="rb_del" id="rb_del_yes" type="radio" value="1">Yes</div><p />
<input type="submit" value="delete article" />
</form>
</body>
</html>

[cleaned up a few other items]

OK, I get that, I understand it, makes sense.
I tried changing a couple of thinmgs based on your bracket explantion,
but when that didn't change anything, I used your example. And even
though it looks like it should work perfectly, it still doesn't do
anything.

Looking at Firefox JavaScript Console, I have this error:

Error: document.getElementById.rd_del_yes has no properties
Source File: index.php?procid=4
Line: 34

Line 34 refering to if (document.getElementById('rb_del_yes').checked).
I don't get it. I changed the id's in the form to match the JS, they're
unique. I even copy-pasted instead of typed them to make sure there's
ni typos and they're exact. How can it not have any properties?
Grr.

Thanks for your reply. And yeah, don't get me started on the new Google
Groups. I've been a user of it since it was deja.com (circa 1999), and
in my opinion they've really screwed it up with this new format. =/

Jul 23 '05 #5
ne**@celticbear.com wrote:
RobB wrote:
LRW wrote:
Having a problem getting a onSubmit function to work, to where it popsup a
confirmation depending on which radiobutton is selected.
function checkdel()
{
if (document.getElementById('rb_del_yes').checked)
return confirm('Are you sure you want to delete this file?');
else return false;
}

//]]>
</script>
</head>
<body>
<form ID="form1" action="index.php?procid=5" method="POST"
target="_self"
enctype="application/x-www-form-urlencoded" onsubmit="return
checkdel()">
<div align="left" class="headerLG">Do you want to delete this

article?
&nbsp;<input name="rb_del" id="rb_del_no" type="radio" value="0"
checked="checked">No
<input name="rb_del" id="rb_del_yes" type="radio"

value="1">Yes</div><p
/>
<input type="submit" value="delete article" />
</form>
</body>
</html>

[cleaned up a few other items]

OK, I get that, I understand it, makes sense.
I tried changing a couple of thinmgs based on your bracket

explantion, but when that didn't change anything, I used your example. And even
though it looks like it should work perfectly, it still doesn't do
anything.

Looking at Firefox JavaScript Console, I have this error:

Error: document.getElementById.rd_del_yes has no properties
Source File: index.php?procid=4
Line: 34

Line 34 refering to if (document.getElementById('rb_del_yes').checked). I don't get it. I changed the id's in the form to match the JS, they're unique. I even copy-pasted instead of typed them to make sure there's
ni typos and they're exact. How can it not have any properties?
Grr.

Thanks for your reply. And yeah, don't get me started on the new Google Groups. I've been a user of it since it was deja.com (circa 1999), and in my opinion they've really screwed it up with this new format. =/


Hope you're both the same person!

Might be having a problem with word-wrap:
enctype="application/x-www-form-urlencoded" onsubmit="return
checkdel()">


....should be all on one line. Thank you usenet.

I won't get you started if you don't get me...started. What a mess.
Half the time I can't even figure out what's going on. Now I just post
to the little box & ignore the big one. Actually works sometimes... :(

Jul 23 '05 #6

RobB wrote:
ne**@celticbear.com wrote:
RobB wrote: Hope you're both the same person!

Might be having a problem with word-wrap:
enctype="application/x-www-form-urlencoded" onsubmit="return
checkdel()">

...should be all on one line. Thank you usenet.

I won't get you started if you don't get me...started. What a mess.
Half the time I can't even figure out what's going on. Now I just

post to the little box & ignore the big one. Actually works sometimes...

:(

Yeah, both me. One from home with a real newsreader, the other from
work on GoogleGroups. =)

No, not word wrap. Everything that needs to be is on one line.
Just doesn't make sense. So basic, so simple, so not working. I'll just
keep playing with it, try to find an alternative. If nothing else I'll
just make a confirmation page on POST. Wanting to avoid that and use JS
before the POST, but oh well.

Thanks for the assistance.
OH, BTW, I haven't see before:
//<![CDATA[

What's that supposed to do?

Thanks,
Liam

Jul 23 '05 #7

ne**@celticbear.com wrote:
RobB wrote:
ne**@celticbear.com wrote:
RobB wrote:
Hope you're both the same person!

Might be having a problem with word-wrap:
> enctype="application/x-www-form-urlencoded" onsubmit="return
> checkdel()">


...should be all on one line. Thank you usenet.

I won't get you started if you don't get me...started. What a mess.
Half the time I can't even figure out what's going on. Now I just

post
to the little box & ignore the big one. Actually works sometimes...

:(

Yeah, both me. One from home with a real newsreader, the other from
work on GoogleGroups. =)

No, not word wrap. Everything that needs to be is on one line.
Just doesn't make sense. So basic, so simple, so not working. I'll

just keep playing with it, try to find an alternative. If nothing else I'll just make a confirmation page on POST. Wanting to avoid that and use JS before the POST, but oh well.

Thanks for the assistance.
OH, BTW, I haven't see before:
//<![CDATA[

What's that supposed to do?

Thanks,
Liam


//<![CDATA[

Keeps scripts from being parsed in xml. OK, this isn't x(ht)ml, it was
left over from elsewhere. People very picky around here about doctypes,
even in demos.

Post what you've got, I guarantee it's something simple. This ain't
rocket science, bear. :0

Jul 23 '05 #8

RobB wrote:
RobB wrote:
ne**@celticbear.com wrote:
//<![CDATA[

What's that supposed to do?

Thanks,
Liam
//<![CDATA[

Keeps scripts from being parsed in xml. OK, this isn't x(ht)ml, it

was left over from elsewhere. People very picky around here about doctypes, even in demos.
Yeah, I asked a question in the HTML Authoring newsgroup once and got a
handful of "your page doesn't validate" and only one reply that
actually tried to help with the actual problem.
Although, because of that I have found out that half of what I knew
about HTML has been depricated since 1996 and I'm learning a lot more
about CSS and W3C. =)
The page below is FAR from validating because I'm not finished with it
yet. Hope that doesn't matter....

Post what you've got, I guarantee it's something simple. This ain't
rocket science, bear. :0


OK, here's the entire page. The JS in question is generated in PHP and
echoed in the HTML. It's something I've done a million times and
haven't had problems, so I don't think that's the issue.

Thanks for the help!
PS: I have no idea how Google's going to CR and display this thing, so
just top be careful, here are just the pertinent lines first, then the
whole page.

$js_add = "<script type=\"text/JavaScript\">
//<![CDATA[
function checkdel() {
if (document.getElementById[\"rd_del_yes\"].checked) {
return alert('Are you sure you want to delete this file?');
else return false;
}
}
//]]>
</script>
";

.............

$maindisplay = "<div align=\"left\" class=\"headerLGX\">News Item
Editor</div><p />
<FORM NAME=\"form1\" ID=\"form1\" action=\"index.php?procid=5\"
method=\"POST\" onSubmit=\"return checkdel();\">
<div align=\"left\" class=\"headerLG\">Do you want to delete this
article? &nbsp;<input name=\"rb_del\" id=\"rb_del_no\" type=\"radio\"
value=\"0\" checked>No <input name=\"rb_del\" id=\"rb_del_yes\"
type=\"radio\" value=\"1\"> Yes </div><p />

Now the whole thing in context....

<?php
/*###########################################
## SET UP DATABASE CONNECTION & PROCESS ID
############################################*/
require_once('../connect.php');
$proc = $_GET['procid'];
$js_add = "";
/*###########################################
## GENERATE APPROPRIATE PAGE
############################################*/
if ($proc == "1") {
// SUBMIT THE NEW ITEM TO DB
$newtitle = $_POST['newtitle'];
$newtext = $_POST['newtext'];
$newdate = date("Y-m-d");
$sql_param = "INSERT INTO tbl_news (news_date,news_title,news_text)
VALUES('$newdate','$newtitle','$newtext')";
$result_param = @mysql_query($sql_param, $connection) or $maindisplay
..= "<br />Could not insert info: ".mysql_error();
if (!mysql_error()){
$maindisplay = "<p /><div align=\"center\" class=\"headerLGX\">Your
article was successfully posted to the site!</div>
<p /><div align=\"center\"><a href=\"../news.php\"
class=\"formlink\">Click here to return to the News Page.</a></div>";
}
} elseif ($proc == "2") {
// ENTER A NEW DATE RANGE
$newdaterange = $_POST['dispdays'];
$sql_param = "UPDATE tbl_params SET par_daterange='$newdaterange'";
$result_param = @mysql_query($sql_param, $connection) or $maindisplay
..= "<br />Could not set parameter info: ".mysql_error();
if (!mysql_error()){
Header("Location: index.php?procid=0");
exit;
}
} elseif ($proc == "3") {
// SELECT AN ARTICLE TO EDIT/DELETE
$sql_edit = "SELECT news_id, news_date, news_title FROM tbl_news
WHERE news_active = '1' ORDER BY news_date DESC";
$result_edit = @mysql_query($sql_edit, $connection) or $maindisplay
..= "<br />Could not querey database: ".mysql_error();
while ($row_edit = mysql_fetch_array($result_edit)) {
$n_id = $row_edit[news_id];
$n_date = $row_edit[news_date];
$n_title = $row_edit[news_title];
$menu .= "<option value=\"".$n_id."\">".$n_date." -
".$n_title."</option>";
}
$maindisplay = "<div align=\"left\" class=\"headerLGX\">Select a past
News Item to Edit or Delete:</div><p />
<form action=\"index.php?procid=4\" method=\"post\"
enctype=\"application/x-www-form-urlencoded\" name=\"form1\"
target=\"_self\"><div align=\"center\"><select
name=\"whichitem\"><option value=\"0\" selected>[ select one
]</option>$menu</select><p /><input type=\"submit\" name=\"Submit\"
value=\"Edit This Item\"></div></form><DIV align=\"center\"
class=\"formQ\"><a href=\"index.php?procid=0\" class=\"formlink\">Click
Here to go back to the News Item Creation page.</a></div>";
} elseif ($proc == "4") {
// EDIT/DELETE AN ARTICLE
$item = $_POST['whichitem'];
$sql_edit = "SELECT news_date, news_title, news_text FROM tbl_news
WHERE news_id = '$item'";
$result_edit = @mysql_query($sql_edit, $connection) or $maindisplay
..= "<br />Could not querey database: ".mysql_error();
while ($row_edit = mysql_fetch_array($result_edit)) {
$e_date = $row_edit[news_date];
$e_title = $row_edit[news_title];
$e_text = $row_edit[news_text];
}
$js_add = "<script type=\"text/JavaScript\">
//<![CDATA[
function checkdel() {
if (document.getElementById[\"rd_del_yes\"].checked) {
return alert('Are you sure you want to delete this file?');
}
}
//]]>
</script>
";
$maindisplay = "<div align=\"left\" class=\"headerLGX\">News Item
Editor</div><p />
<FORM NAME=\"form1\" ID=\"form1\" action=\"index.php?procid=5\"
method=\"POST\" onSubmit=\"return checkdel();\">
<div align=\"left\" class=\"headerLG\">Do you want to delete this
article? &nbsp;<input name=\"rb_del\" id=\"rb_del_no\" type=\"radio\"
value=\"0\" checked>No <input name=\"rb_del\" id=\"rb_del_yes\"
type=\"radio\" value=\"1\"> Yes </div><p />
<TABLE align=\"center\" width=\"90%\" border=\"0\"
cellpadding=\"5\" cellspacing=\"5\">
<TR>
<TD align=\"right\" class=\"headerLG\">Title:</TD>
<TD><INPUT type=\"text\" name=\"newtitle\" size=\"40\"
value=\"".$e_title."\"></TD>
</TR>
<TR>
<TD align=\"right\" valign=\"top\" class=\"headerLG\">Text:</TD>
<TD><textarea name=\"newtext\" cols=\"60\" rows=\"20\"
wrap=\"virtual\">".$e_text."</textarea></TD>
</TR>
<TR>
<TD align=\"center\" colspan=\"2\"><INPUT type=\"submit\"
name=\"submitart\" value=\"Submit Changes\"></TD>
</TR>
</TABLE>
</FORM>";
} elseif (($proc == "0") || ($proc == "")) {
// ENTER A NEW ARTICLE FORM
$sql_param = "SELECT * FROM tbl_params";
$result_param = @mysql_query($sql_param, $connection) or $maindisplay
..= "<br />Could not get parameter info: ".mysql_error();
while ($row_p = mysql_fetch_array($result_param)) {
$daterangenum = $row_p[par_daterange];
}
$maindisplay = "<div align=\"left\" class=\"headerLGX\">Submit a New
Item for the News &amp; Events Page</div>
<DIV align=\"center\" class=\"formQ\"><a href=\"index.php?procid=3\"
class=\"formlink\">Click Here if you want to EDIT or DELETE a past News
Item.</a></div><br />
<FORM action=\"index.php?procid=2\" method=\"POST\"
enctype=\"application/x-www-form-urlencoded\" target=\"_self\">
<div align=\"center\" class=\"formQ\"><b>How many days back do you
want visible on the page? (eg: 7 or 30 or 90 or 365...)</b><br />
<INPUT type=\"text\" name=\"dispdays\" size=\"4\"
value=\"".$daterangenum."\"><INPUT type=\"submit\" name=\"submit\"
value=\"Press to Change Date Range\"></div>
</FORM>
<FORM action=\"index.php?procid=1\" method=\"POST\"
enctype=\"application/x-www-form-urlencoded\" target=\"_self\">
<TABLE align=\"center\" width=\"90%\" border=\"0\"
cellpadding=\"5\" cellspacing=\"5\">
<TR>
<TD align=\"right\" class=\"headerLG\">Title:</TD>
<TD><INPUT type=\"text\" name=\"newtitle\" size=\"40\"></TD>
</TR>
<TR>
<TD align=\"right\" valign=\"top\" class=\"headerLG\">Text:</TD>
<TD><textarea name=\"newtext\" cols=\"60\" rows=\"20\"
wrap=\"virtual\"></textarea></TD>
</TR>
<TR>
<TD align=\"center\" colspan=\"2\"><INPUT type=\"submit\"
name=\"submitart\" value=\"Submit New Article\"></TD>
</TR>
</TABLE>
</FORM>
";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>news.jpg</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
/* Functions that swaps images. */
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array;
for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc)
x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr;
for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/* Functions that handle preload. */
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0;
i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image;
d.MM_p[j++].src=a[i];}}
}
//-->
</script>
<?=$js_add;?>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
..r5_c1 { background-image: url(../images/news_r5_c1.jpg) };
..formQ {
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 12px;
font-weight: normal;
color: #333333;
}
..formlink {
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 12px;
font-weight: normal;
}
a.formlink {
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 12px;
font-weight: normal;
color: #000066;
text-decoration: underline;
}
a.formlink:hover {
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 12px;
font-weight: normal;
color: #0000FF;
text-decoration: none;
}
..headerLG {
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 12px;
font-weight: bold;
color: #000000;
}
..headerLGX {
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 18px;
font-weight: bold;
color: #000000;
}
-->
</style>
</head>
<body bgcolor="#46311f"
onLoad="MM_preloadImages('../images/news_r2_c2_f2.jpg','../images/news_r2_c4_f2.jpg','../images/news_r2_c7_f2.jpg','../images/news_r2_c10_f2.jpg','../images/news_r7_c5_f2.jpg');">
<table width="770" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr><!-- row 1 -->
<td><img name="news_r1_c1" src="../images/news_r1_c1.jpg"
width="770" height="129" border="0" alt=""></td>
</tr>
<tr><!-- row 2 -->
<td><table align="left" border="0" cellpadding="0" cellspacing="0"
width="770">
<tr><!-- row 1 -->
<td><img name="news_r2_c1" src="../images/news_r2_c1.jpg"
width="105" height="24" border="0" alt=""></td>
<td><a href="../thebook.html" onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('news_r2_c2','','../images/news_r2_c2_f2.jpg',1);"><img
name="news_r2_c2" src="../images/news_r2_c2.jpg" width="127"
height="24" border="0" alt=""></a></td>
<td><img name="news_r2_c3" src="../images/news_r2_c3.jpg"
width="36" height="24" border="0" alt=""></td>
<td><a href="../index.html" onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('news_r2_c4','','../images/news_r2_c4_f2.jpg',1);"><img
name="news_r2_c4" src="../images/news_r2_c4.jpg" width="49" height="24"
border="0" alt=""></a></td>
<td><img name="news_r2_c6" src="../images/news_r2_c6.jpg"
width="41" height="24" border="0" alt=""></td>
<td><a href="../purchase.html" onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('news_r2_c7','','../images/news_r2_c7_f2.jpg',1);"><img
name="news_r2_c7" src="../images/news_r2_c7.jpg" width="116"
height="24" border="0" alt=""></a></td>
<td><img name="news_r2_c8" src="../images/news_r2_c8.jpg"
width="43" height="24" border="0" alt=""></td>
<td><a href="../author.html" onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('news_r2_c10','','../images/news_r2_c10_f2.jpg',1);"><img
name="news_r2_c10" src="../images/news_r2_c10.jpg" width="144"
height="24" border="0" alt=""></a></td>
<td><img name="news_r2_c11" src="../images/news_r2_c11.jpg"
width="109" height="24" border="0" alt=""></td>
</tr>
</table></td>
</tr>
<tr><!-- row 3 -->
<td><img name="news_r3_c1" src="../images/news_r3_c1.jpg"
width="770" height="10" border="0" alt=""></td>
</tr>
<tr><!-- row 4 -->
<td><img name="news_r4_c1" src="../images/news_r4_c1.jpg"
width="770" height="95" border="0" alt=""></td>
</tr>
<tr><!-- row 5 -->
<td class="r5_c1"><table width="100%" border="0" cellspacing="0"
cellpadding="0">
<tr>
<td width="6%">&nbsp;</td>
<td width="88%"><?=$maindisplay;?></td>
<td width="6%">&nbsp;</td>
</tr>
</table></td>
</tr>
<tr><!-- row 6 -->
<td><img name="news_r6_c1" src="../images/news_r6_c1.jpg"
width="770" height="87" border="0" alt=""></td>
</tr>
<tr><!-- row 7 -->
<td><table align="left" border="0" cellpadding="0" cellspacing="0"
width="770">
<tr><!-- row 1 -->
<td><img name="news_r7_c1" src="../images/news_r7_c1.jpg"
width="283" height="22" border="0" alt=""></td>
<td><a href="http://www.ie-studios.net"
onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('news_r7_c5','','../images/news_r7_c5_f2.jpg',1);"><img
name="news_r7_c5" src="../images/news_r7_c5.jpg" width="206"
height="22" border="0" alt=""></a></td>
<td><img name="news_r7_c9" src="../images/news_r7_c9.jpg"
width="281" height="22" border="0" alt=""></td>
</tr>
</table></td>
</tr>
<tr><!-- row 8 -->
<td><img name="news_r8_c1" src="../images/news_r8_c1.jpg"
width="770" height="11" border="0" alt=""></td>
</tr>
</table>
</body>
</html>

Jul 23 '05 #9
Dude....

$js_add = "<script type=\"text/JavaScript\">
//<![CDATA[
function checkdel() {
if (document.getElementById-----------> [\"rd_del_yes\"] <-------------
return alert('Are you sure you want to delete this file?');
}
}

Go back & read my first reply:
It's document.getElementById() - a function. Parentheses; square
brackets are for object/array references.


hth :)

Jul 23 '05 #10

RobB wrote:
Dude....

$js_add = "<script type=\"text/JavaScript\">
//<![CDATA[
function checkdel() {
if (document.getElementById-----------> [\"rd_del_yes\"] <------------- return alert('Are you sure you want to delete this file?');
}
}

Go back & read my first reply:
It's document.getElementById() - a function. Parentheses; square
brackets are for object/array references.


hth :)


OK, I am indeed a dumbss. And my dumbssness has wasted some time and
effort and patience. =) Unfortunately, correcting my error still didn't
fix anything.
Here is what I have now (I've put the JS in the HTML this time instead
of having PHP echo it. Thought I'd try that to eliminate any problems
with that I'm missing)

<script type="text/JavaScript">
//<![CDATA[
function checkdel() {
if (document.getElementById('rd_del_yes').checked) {
return confirm('Are you sure you want to delete this file?');
} else {
return false;
}
}
//]]>
</script>

You will note the parentheses and single-quotes now instead of brackets
and doublequotes. =)

This is really weird...even though I have it in singlequotes, when I
refresh the page and look at Firfox's JS Console, it says:

Error: document.getElementById("rd_del_yes") has no properties
Source File: index.php?procid=4
Line: 33

Why would it be showing doublequotes? In "Page Source" it has only
single-quotes. Likely unrelated, though?

$maindisplay = "<div align=\"left\" class=\"headerLGX\">News Item
Editor</div><p />
<FORM NAME=\"form1\" ID=\"form1\" action=\"index.php?procid=5\"
method=\"POST\" onSubmit=\"return checkdel();\">
<div align=\"left\" class=\"headerLG\">Do you want to delete this
article? &nbsp;<input name=\"rb_del\" id=\"rb_del_no\" type=\"radio\"
value=\"0\" checked>No <input name=\"rb_del\" id=\"rb_del_yes\"
type=\"radio\" value=\"1\"> Yes </div><p />
<TABLE align=\"center\" width=\"90%\" border=\"0\" cellpadding=\"5\"
cellspacing=\"5\">
....

Sorry.

Jul 23 '05 #11
celticbear.com wrote:
I am indeed a dumbss [sic]


Erm, well.............

checkbox id ---------> id=\"rb_del_yes\"
script reference ----> "rd_del_yes"

I've never understood why NS/mozilla always reports "Blah has no
properties..." when they mean "Blah doesn't exist."
Why be cute about it? ( like MSIE "Object Expected" [ FUNCTION !!! ] )

Jul 23 '05 #12
Lee
LRW said:

Having a problem getting a onSubmit function to work, to where it popsup a
confirmation depending on which radiobutton is selected.
Here's what I have:

function checkdel() {
if (document.getElementById["rd_del[]"].value=='1') {
confirm('Are you sure you want to delete this file?');
}
}
.....
<FORM NAME="form1" ID="form1" action="index.php?procid=5" method="POST"
enctype="application/x-www-form-urlencoded" target="_self" onSubmit="return
checkdel();">
<div align="left" class="headerLG">Do you want to delete this article?
&nbsp;<input name="rb_del" id="rb_del" type="radio" value="0" checked>No
<input name="rb_del" id="rb_del" type="radio" value="1"> Yes </div><p />
I've tried:
document.getElementById["rd_del"].value=='1'
document.getElementById["rd_del[1]"].checked==true

I've looked up DOM and looked for examples, and from what I can see, I have
it formatted correctly.
I've also tried syntax that's put the 'form1' in the line above, but I just
can't make it work.
What am I missing? Just a clue would help!


I think you've got a logic error as well as coding problems.
I'm guessing that what you really want to do is:

if "no" is checked, submit the form.
if "yes" is checked, submit only if they confirm.

If that's the case, here's a solution. You avoid getElementById() altogether by
passing a reference to the "no" checkbox. If that box is checked, you return
true and allow the form to submit. If it is not checked (then "yes" must be
checked), you return the value returned by confirm():
<html>
<head>
<title>demo</title>
<script type="text/javascript">
function checkdel(delRadio) {
return delRadio.checked || confirm('Are you sure you want to delete this
file?');
}
</script>
</head>
<body>
<form name="form1"
id="form1"
action="index.php?procid=5"
method="POST"
enctype="application/x-www-form-urlencoded"
target="_self"
onsubmit="return checkdel(rb_del[0]);">

Do you want to delete this article? &nbsp;
<input name="rb_del" id="rb_deln" type="radio" value="0" checked> No
<input name="rb_del" id="rb_dely" type="radio" value="1"> Yes
<br>
<input type="submit">
</form>
</body>
</html>

Jul 23 '05 #13
::hangs head in mortal shame::
I'll be going to commit ritual seppuku now. It appears I have a fatal
case of stupidity.

I could have sworn I copy-n-pasted the ID names. Could have sworn. I
didn't even bother to check them as closely as I should have because
I'd thought I'd copy-n-pasted them.
My sincere appologies for dragging you down this rediculous road of my
moronathon.

Thanks for your help and patience.
Liam

Jul 23 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Les Juby | last post: by
10 posts views Thread by Mike Malter | last post: by
5 posts views Thread by Vear | last post: by
7 posts views Thread by Trickynick1001 | last post: by
4 posts views Thread by tfsmag | last post: by
8 posts views Thread by Eric | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.