473,322 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Onclick Alert popup in php

24
The "filetest.txt" contents is here
..................
one/yes
two/no
three/maybe
four/fun
five/ok
................

The main program is here
..........................
<?php
srand((double) microtime() * 1000000);
$readfile = file("filetest.txt");
$k=rand(0, sizeof($readfile)-2);
list($quest,$answ) = split("/",$readfile[$k]);
print("$quest<BR>$answ<br>");
?>
<button onClick="alert('Question is : <?=$quest?>')">Question1</button>
<button onclick="alert(<?php echo "'Question is : " . $quest ."'"; ?>)">Question2</button><BR>
<button onClick="alert('Answer is : <?=$answ?>')">Answer1</button>
<button onclick="alert(<?php echo "'Answer is : " . $answ ."'"; ?>)">Answer2</button>
<script>
<?php echo "var V='" . $answ ."';"; ?>
</script>
<button onclick="alert(V)">click</button>
............................................

All the above "alert" popups work with the "Question" ($quest), or first item after reading the text file.
But none of them work with the "Answer" ($answ), or the second item in text file. Why?
Sep 14 '06 #1
2 43237
raji20
28
The "filetest.txt" contents is here
..................
one/yes
two/no
three/maybe
four/fun
five/ok
................

The main program is here
..........................
<?php
srand((double) microtime() * 1000000);
$readfile = file("filetest.txt");
$k=rand(0, sizeof($readfile)-2);
list($quest,$answ) = split("/",$readfile[$k]);
print("$quest<BR>$answ<br>");
?>
<button onClick="alert('Question is : <?=$quest?>')">Question1</button>
<button onclick="alert(<?php echo "'Question is : " . $quest ."'"; ?>)">Question2</button><BR>
<button onClick="alert('Answer is : <?=$answ?>')">Answer1</button>
<button onclick="alert(<?php echo "'Answer is : " . $answ ."'"; ?>)">Answer2</button>
<script>
<?php echo "var V='" . $answ ."';"; ?>
</script>
<button onclick="alert(V)">click</button>
............................................

All the above "alert" popups work with the "Question" ($quest), or first item after reading the text file.
But none of them work with the "Answer" ($answ), or the second item in text file. Why?




TRy this code
The problem is that there is the new line after the answer, so i have used trim function to remove the white spaces, and its working fine.

<?php
srand((double) microtime() * 1000000);
$readfile = file("filetest.txt");
$k=rand(0, sizeof($readfile)-2);
list($quest,$answ) = split("/",$readfile[$k]);
print("$quest<BR>$answ<br>");
$answ = trim($answ);
?>
<button onClick="alert('Question is : <?=$quest?>')">Question1</button>
<button onclick="alert(<?php echo "'Question is : " . $quest ."'"; ?>)">Question2</button><BR>
<button onClick="alert('Answer is : <?=$answ?>')">Answer1</button>
<button onclick="alert(<?php echo "'Answer is : " . $answ ."'"; ?>)">Answer2</button>
<script>
<?php echo "var V='" . $answ ."';"; ?>
</script>
<button onclick="alert(V)">click</button>
Sep 14 '06 #2
jrsjrs
24
Thank you very much raji20. It works perfectly now!
I was not aware that a carriage return needed a "trim".

Would you or anyone else know how to change this script
so that the alert popup is triggered from clicking on
an image or a word (like a link) instead of on a button?
Sep 15 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dipin | last post by:
Hi All; I have this javascript which is adding a new button to the column in the row which is created dynamically, the innerhtml shows that the onclick event is correctly added but it never gets...
2
by: Sharon | last post by:
Hi y'all, I'm trying to create a customized context menu using the DHTML Popup object. The HTML that makes up the body of the popup is created in a variable named 'popCode'. Works like a charm,...
17
by: Mike Gratee | last post by:
Is it possible to use JavaScript to cause the browser to click a link on a page and have the browser act exactly like the user had clicked on the link directly? In other words, I need to...
15
by: | last post by:
So many websites can get around my Googlebar's popup blockers. Even Opera 8 can not stop those popups. I looked into the codes, and I can find nothing showing me how it is done. Can anyone help me...
13
by: crjunk | last post by:
Should I expect some of my users to not be able to view a report that I am launching in a new web browser if they have any popup blocking tool bars or other software installed on their computer? ...
5
by: VA | last post by:
Firefox 1.0.7 If I launch Jesse Ruderman's Javascript shell http://www.squarefree.com/2005/10/30/javascript-shell-14/ on any web page and type in the shell var mylink for...
3
by: lohithb | last post by:
Hi, I have used javascript onclick event handler. But, in ssl a security alert is displayed when the event is generated. So can i give me a solution for this other than the settings in the browser...
4
by: Paul Furman | last post by:
I can't find a way to create an alert popup box for debugging, is this possible in php? I guess I'm thinking of visual basic where that was so easy, in php I normally use *print* for this but it...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.