2

I'm newbie in jquery And Data table, I have problem when to set value for element input from another page using function.

this my 1st page code

{
                data: "action_user",
                targets: "action_user",
                mRender: function (data_app, type_app, row_app) {
                    if (row_app["id_user"] !== null) {
                        var va_id_user = row_app["id_user"];
                        var va_user_name = row_app["user_name"];
                        var va_gender = row_app["gender"];
                        var va_address = row_app["address"];
                        var va_imei = row_app["imei"];                        
                        var va_phone = row_app["phone"];
                        var va_role_name = row_app["role_name"];
                        var va_email = row_app["email"]; //,supplier_name,supplier_code,address,contact_name,contact_num,status_supp
                        var va_status_user = row_app["status_user"]; // <a href='#'id='updateDataUser' onclick='javascript:myFunc(" + supplier_id + ")'><i class='fa fa-edit'title='Edit'></i></a>\n\

                        var data_users = {
                            id_user: va_id_user,
                            user_name: va_user_name,
                            gender: va_gender,
                            imei: va_imei,
                            phone:va_phone,
                            address:va_address,
                            role_name: va_role_name,
                            email: va_email,
                            status_user: va_status_user
                        };
                        return"<a id='updateDataUser' href='#' onclick='javascript:editUserFunc(" + JSON.stringify(data_users) + ")'><i class='fa fa-edit activeRecord' rel='13' title='Edit'></i></a>";
//                      return "<a href='" + data_pict_1 + " 'target='_blank' class='btn btn-info'>" + "<font color='#f2f2f2' size='2em'>" + "Display" + "</font>" + "</a>";
                    }
                }
            }

this my html code

<div id="div_add_pic" class="panel panel-default">
  <form id="form_add_pic" name="form_add_pic" method="POST" action="">
    <div id="form_add_user_response" class="resp"></div>
    <div class="box-body">
      <div class="form-group">
        <label for="username" class="req">User Name &nbsp;:</label>
    <input type="text" name="userName" id="userName" placeholder="User Name" class="form-control  uppercase" />

      </div>
    </div>
  </form>
</div>

this my function to set input value element .

function editUserFunc(data_users) {
var userName = data_users.user_name;
alert(userName);
$("#userName").val(userName);}

my function I change to

    function editUserFunc(data_users) {
        var userName = data_users.user_name;
         alert(userName);
        var oForm = document.getElementById("form_add_pic");
        var set_userName = oForm.userName;

 window.location.href = "index.jsp?url=user_layout&   pages=add_user_form"
    }

but I've got error

validation.js:1422 Uncaught TypeError: Cannot read property 'userName' of null
at editUserFunc (validation.js:1422)
at HTMLAnchorElement.onclick (index.jsp?url=user_layout&pages=list_users:1)

my console.log printscreen console userName

how to call the element form on another page

I have tried it many times but I've been unsuccessful. Please help!

6
  • What is actually the problem you are facing here? Any errors in console? Please explain the problem. Commented Sep 19, 2018 at 10:30
  • Set the id username to the label Commented Sep 19, 2018 at 10:32
  • I Set the id username to the label, it still doesn't work Commented Sep 24, 2018 at 10:07
  • Can you check what actually gets passed to your .editUserFunc()? Maybe with console.log(data_users). If the data gets passed, try to reconvert to JSON with JSON.parse(data_users) before you access its properties. Commented Sep 24, 2018 at 10:36
  • this my print screen to console log i.sstatic.net/srzV0.png Commented Sep 24, 2018 at 10:56

2 Answers 2

0

I think, you have to move all these functions inside

$(document).ready(function(){

//Replace with your code

})

Because your script may be there in top of html tags and while running these scripts, those html inputs are not loaded.

Sign up to request clarification or add additional context in comments.

Comments

0

finally I use this code, to get parameter on url address bar

function getUrlQueryString(param) {
var outObj = {};
var qs = window.location.search;
 if (qs != "") {
  qs = decodeURIComponent(qs.replace(/\?/, ""));
  var paramsArray = qs.split("&");
  var length = paramsArray.length;
  for (var i=0; i<length; ++i) {
     var nameValArray = paramsArray[i].split("=");
     nameValArray[0] = nameValArray[0].toLowerCase();
     if (outObj[nameValArray[0]]) {
        outObj[nameValArray[0]] = outObj[nameValArray[0]] + ";" + nameValArray[1];
        }
     else {
        if (nameValArray.length > 1) {
           outObj[nameValArray[0]] = nameValArray[1];
           }
        else {
           outObj[nameValArray[0]] = true;
           }
        }
     }
  }
 var retVal = param ? outObj[param.toLowerCase()] : qs;
 return retVal ? retVal : ""
}

Comments

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.