1

Alright, basically I've got a php page we'll call form.php. This page contains a form with a date selector, time selector and textbox (input type="date" input type="time" input type="textarea"). When the user submits the form, the information is sent to the mysql database, and outputted on the next page "display.php".

All of this works perfectly fine. The display.php page is made from the code within form.php ie. <h1>This is the header</h1> <h2 class="date">$date</h2> <h3 class="time">$time</h3> <p class="message">$message</p>

The output in display.php is


This is a header
2012-04-23
00:59
My message
a button (just to check my work currently)


I am trying to use jquery like so

$(document).ready(function(){ 
$('button').mousedown(function(){ 

if ($('h3').text() == "00:59") {
alert("Yup"); return true;}
 else { alert("Nope");return false;};
});
 });

This will not work to match the time, the date, or the message. If I run the exact same code but search for the h1 that wasn't created with a variable, that will work ie.

 $(document).ready(function(){ 
$('button').mousedown(function(){ 

if ($('h1').text() == "This is a header") {
alert("Yup"); return true;}
 else { alert("Nope");return false;};
});
 });

I can't figure out what I'm missing here.

I can even change the h1 to 00:59, run the jquery searching for h1 == "00:59" and it will return true and pass the alert.

It's when I go after the h2, h3, and p elements that were created from the php variables ($time, $date, $message)

Any help would be much appreciated.

2
  • Try alerting $('h3').text() and check. Commented May 24, 2013 at 6:30
  • I could be wrong but I think your missing the concept of what I'm trying to do (I'm a noob so believe me I'm not saying your wrong haha as I most likley am) The idea is to input a "schedule item" on form.php like "2013-05-24, 11:00, do laundry" On the display.php page, I jquery to find that 11:00 and set an alert. The full functionality when finished would be to check the local time and compare, but I'm very basic at this so currently I just want to do it as if I say.. if h2 is 11:00 alert YUP. I can't seem to target any elements that were created with the php variables ($time, $date)etc Commented May 24, 2013 at 6:42

2 Answers 2

0

try to close <p> element correctly:

<h1>This is the header</h1>
<h2 class="date">$date</h2>
<h3 class="time">$time</h3>
<p class="message">$message</p>
Sign up to request clarification or add additional context in comments.

Comments

0

Have you checked that the created h3 don't contain any encoded or hidden chars? That could cause your check to fail since you check for text you see, not the actual text within the tag. Don't think any of the chars you use are usually encoded though, but worth a look.

Running your code in jsfiddle as IF it actually contained the correct text it works fine. So there must be some kind of mismatch between what you check for and what is actually in the tag.

Code tested

HTML

<h1>This is the header</h1> <h2 class="date">2012-04-23</h2> <h3 class="time">00:59</h3> <p class="message">My message</p>
<button>Test</button>

Javascript

$(document).ready(function(){ 
$('button').mousedown(function(){ 

if ($('h3').text() == "00:59") {
alert("Yup"); return true;}
 else { alert("Nope");return false;};
});
 });

6 Comments

I can create an <h1> that says "00:59" in the form.php page where I generate how the html will show up on display.php, search for it with the jquery script and it will work. If the <h3> that was generated from $time is searched though, it can't find the "00:59". It's only the text that was created from variables that seems to be unsearchable.
ie. ` <div class="post" name="post" > <h1>00:59</h1> <h2 name="date"> $date </h2> <h3 class="time"> $time </h3> <p id="agenda"> $bodytext </p> </div>` On the output page, the jquery works perfect to find the text string "00:59" of h1. Now say I delete h1, and the time I set was "00:59" (or anytime) I cannot use the same jquery code to find it. I'm not sure if I'm explaining this properly..
If i had my $bodytext output equal "hello world" and searched for that with the jquery script, it won't find it, it comes back false. It seems to only be doing this with ones that were posted from the form.php to the database and outputted on the display.php page.
As for hidden or encoded, I've looked over the source code, console, everything I can think of and it looks just as expected
I reposted with full code stackoverflow.com/questions/16729787/… to maybe give a better overview of the issue
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.