Welcome Guest, Not a member yet? Register   Sign In
undefined index:button.- what's the problem
#1

[eluser]cinewbie81[/eluser]
View File
Code:
// HTML code for Edit button
<input type="image" name="edit" onclick="GetRecord(this);return false;" src="<?php echo base_url();?>images/edit.gif" value="Edit" alt="Edit" title="Edit Record" height="50px" width="40">

Javascript file - after Edit utton clicked
Code:
function GetRecord (button)
{
    var form_id = document.getElementById('form_id');
    var checked_values='';
    for (a=0; a<form_id.elements.length; a++)
    {
        if (form_id.elements[a].type == 'checkbox'
            && form_id.elements[a].name == 'checkbox')
        {
            if (form_id.elements[a].value && form_id.elements[a].checked)
            {
                checked_values += form_id.elements[a].value;
                break;
            }
        }
    }
    runAction(button,checked_values);
    return false;
}

function runAction(button,str)
{
    if (str == '') {
        alert('Please make a selection from the list');
        return;
    }
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    }
    xmlHttp.onreadystatechange=actionstatechange;
    var url =  
        button.par[b][/b]entNode.pare[b][/b]ntNode.action+"?button="+button.name+"&d;="+str+"&sid;="+Math.random();
    window.l[b][/b]ocation.href = url;
    return false;
}


My Controller file
Code:
function action()
{
    if ($_REQUEST['button'] == 'edit') {
        // Perform Edit here
    }
}


When the system go to the action function shown above, it give me the following error:

A PHP Error was encountered
Message: undefined index:button.

It's work in Firefox, and works in my Testing PC (which is both IE 6 and 7) ... Anyway, some my clients who are using IE7 having the problem mentioned above each time they click the EDIT button. WHat's wrong with the code, any idea?
#2

[eluser]Pascal Kriete[/eluser]
Hmm, it's a little tough to understand at the end. My non-framework ajax is a little rusty and the forum added a few too many [removes].

[quote author="cinewbie81" date="1201591213"]both IE 6 and 7[/quote]
Did I miss something? Doesn't IE6 need an ActiveX Object?

And just a little pet-peeve of mine. How are people who have js disabled going to edit?
#3

[eluser]cinewbie81[/eluser]
Hi, in order to bypass the [remove] thingy, i use instead ..
So how should I solve the problem if the user doesnt have the Javascript Enable ? Is it the only way to ask them 'Enabled' it ??

What if they think it's a system bug or something because sometimes a user wont even know what javascript is !!
#4

[eluser]Pascal Kriete[/eluser]
Basically what you do is you create regular form. And then you layer javascript on top of it using event handlers.

A simple example just to demonstrate the point (using prototype - I hate writing regular js).

The Form
Code:
&lt;form action="somewhere/where/theform/isprocessed" method="post" id="report_form" accept-charset="utf-8"&gt;
Name:<br/>
&lt;input type="text" name="name" value="" id="name"&gt;<br/><br/>
<p>&lt;input type="submit" id="submit_form" value="Report"&gt;</p>
&lt;/form&gt;
<p id='ajax_result'></p>

In your page head:
Code:
&lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;
&lt;!--
    function init() {
        $('submit_form').observe('click', report);
    }

    function report(event) {
        event.stop();
        new Ajax.Updater('ajax_result', 'omewhere/where/theform/isprocessed/ajax', {
            parameters: { name: $F('name') },
            method: 'post',
            onCreate: function() {
                $('report_form').update('Submitting...<br/>');
            }
        });
    }
        
    document.observe('dom:loaded', init);
    
//--&gt;
&lt;/script&gt;

In this example I would need two backend scripts. One to handle regular form submittions, and one to handle the ajax calls (they really only differ in what they return). Basically what happens is that when javascript is disabled the user just submits normally. When javascript is active, it catches the click on the submit button and runs an asynchronous query, the result of which is displayed in ajax_result. It makes for much more accessible websites, and also keeps your main body free of javascript.




Theme © iAndrew 2016 - Forum software by © MyBB