473,569 Members | 2,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Onclick Alert popup in php

24 New Member
The "filetest.t xt" 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($readfil e)-2);
list($quest,$an sw) = split("/",$readfile[$k]);
print("$quest<B R>$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?>')">A nswer1</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 43269
raji20
28 New Member
The "filetest.t xt" 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($readfil e)-2);
list($quest,$an sw) = split("/",$readfile[$k]);
print("$quest<B R>$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?>')">A nswer1</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($readfil e)-2);
list($quest,$an sw) = split("/",$readfile[$k]);
print("$quest<B R>$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?>')">A nswer1</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 New Member
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
39446
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 invoked when I click it. newcol = doc.createElement("TD"); newbutton = doc.createElement("input"); newbutton.name = "newChange"+__uid;
2
1615
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, except when I call a function in an onclick it gives an 'object expected' error. Here's the popup function (dopopup) and the function I'm calling...
17
61413
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 programmatically issue a JavaScript statement which causes the browser to act just like the user clicked on a link in my page. And if that link has an...
15
18712
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 find what how it is done? First go to http://www.sitepoint.com/forums/showthread.php?t=184025&page=1&pp=25 Click on Last ? on the page
13
2806
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? <input type="button" value="View MPR For This Location" onClick="javascript:popUp(''http://MyServer/MPR_Report/ViewReport.aspx?fn=12345'')"> ...
5
2020
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 (j=0;j<document.links.length;j++) {
3
3344
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 preferences.
4
32414
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 can be hard to find. thanks
0
7694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.